Search code examples
ruby-on-railsfavorites

Hearing in Rails Syntax Error


New to Rails, trying to add a favorites, using hearts on posts in my app and dont know why I'm getting this sytax error. Have followed the tutorial step by step.Is this somethong obvious ?

/Users/leehumphreys/Desktop/with hearts favorites/app/views/rooms/show.html.erb:292: unterminated string meets end of file /Users/leehumphreys/Desktop/with hearts favorites/app/views/rooms/show.html.erb:292: syntax error, unexpected end-of-input, expecting ')'

 <% @rooms.each do |room| %>
  <%= room.title %>
  <%= div_for room do %>
     render "hearts/button”, room: room 
    <% end %>
  <% end %

Actually getting the error at <% @rooms.each do |room| %>


Solution

  • First:

    <% room.title %>
    

    won't do anything because you need to output the result, thus:

    <%= room.title %>
    

    Then, you have one too many end. You only need to close one bock:

    <%= room.title %>
    <%= div_for room do %>
      <%= render partial: "hearts/button”, locals: { room: room } %>
    <% end %>
    

    Basically, your end is a completion for do. Every do starts a block, which must end with an end.

    Also note your render can be simplified as such:

    render "hearts/button”, room: room
    

    Update after comment to answer:

    <% @rooms.each do |room| %>
      <%= room.title %>
      <%= div_for room do %>
        <%= render "hearts/button”, room: room  %>
      <% end %>
    <% end %>
    

    I suggest you take a look at some erb tutorial, this one for example.