Home>
Cooking-like web services like cookpad are made with rails.
So I'm thinking about making a pasta-only page.
I want to realize where I search for data that has pasta in the chef column of the Cookings table and return name/image/text to the/cookings/pasta view using each statement.
It may be easy, but I would love to hear from you.
I don't get an error message, but I would like to erase the sequence that would have been received at @cookings = Cooking.where (chef: "pasta") at the end.
Error message
Applicable source code
cookings_cotroller
def pasta
@cookings = Cooking.where (chef: "pasta")
end
/cookings/pasta.html.erb
<% = @ cookings.each do | cooking |%>
<p><% = cooking.name%></p>
<p><% = image_tag cooking.image.url%></p>
<p><% = cooking.text%></p>
<% end%>
routes.rb
Rails.application.routes.draw do
devise_for: users
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'cookings # index'
get '/ cookings/new' =>'cookings # new'
post '/ cookings' =>'cookings # create'
get '/ cookings/pasta' =>'cookings # pasta'
end
Usebinding.pry to confirm that the expected sequence is included in @cookings.
Without the each statement, the last array was never displayed.
Please provide more detailed information here.
-
Answer # 1
Related articles
- ruby - i want to hide a specific record
- ruby on rails - i want to know how to return from rails api mode to non-api mode (normal rails)
- ruby - i want to display specific columns in rails in descending order of numbers
- ruby on rails 5 - child model record not created
- ruby on rails - how to test that a specific element has a class name using rspec/capybara
- ruby on rails - extract multiple specific columns from one activerecord and make them json
- ruby - [rails 5] i want to send an email to a specific user using action mailer
- ruby on rails 5 - transaction exception handling doesn't work
- ruby on rails - how to debug with rails pry in docker environment
- ruby on rails - rails60 i can't log in
- ruby on rails - i get an error without being created
- ruby on rails 6 - when i press new user registration, i get an error of no route matches [get] "/ users"
- ruby on rails - [rails] the initial image of the icon for the user is not displayed
- ruby on rails - i want to write a rails tutorial test in rspec
- ruby - i want to output csv with narrowed down conditions with rails
- ruby on rails - error when implementing rails6 follow function
- ruby - i can't transition to my page for each user after logging out (rails)
- ruby on rails - the value of find_by (id :) becomes nil
- ruby - unable to save comments in db (rails)
- ruby - rails: fattachment_field gives undefined method error
Trends
Since
<% =%>
is used, the return value ofeach
(@cookings
itself) is output.Use
<%%>
to embed without output.