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.

Error message

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


def pasta
      @cookings = Cooking.where (chef: "pasta")


<% = @ cookings.each do | cooking |%>
   <p><% = cooking.name%></p>
   <p><% = image_tag cooking.image.url%></p>
   <p><% = cooking.text%></p>
<% end%>


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'

binding.pry to confirm that the expected sequence is included in @cookings.
Without the each statement, the last array was never displayed.

Supplemental information (FW/tool version etc.)

Please provide more detailed information here.

  • Answer # 1

    <% = @ cookings.each do | cooking |%>

    Since<% =%>is used, the return value ofeach(@cookingsitself) is output.
    Use<%%>to embed without output.

Related articles