简体   繁体   中英

Syntax error, unexpected '\n', expecting tCOLON2 or '[' or '.'

I'm getting the following error on a simple test app I am working on to learns Rails.

syntax error, unexpected '\n', expecting tCOLON2 or '[' or '.'

It appears that it's telling be that there is an undexpected break, but I can't figure out what is wrong with my code below:

#app/views/quotations/index.html.erb
<% title "Quotations" %>

<table>
  <tr>
    <th>Quote Text</th>
    <th>Author</th>
    <th>Quote type</th>
    <th>Category</th>
    <th>Tags</th>
  </tr>
  <% for @quotations.each do |quotation| %>
    <tr>
      <td><%= quotation.quote_text %></td>
      <td><%= quotation.author %></td>
      <td><%= quotation.quote_type %></td>
      <td><%= quotation.category %></td>
      <td><%= quotation.tags %></td>
      <td><%= link_to "Show", [@user, quotation] %></td>
      <td><%= link_to "Edit", edit_user_quotation_path(@user, quotation) %></td>
      <td><%= link_to "Destroy", [@user, quotation], :confirm => 'Are you sure?', :method => :delete %></td>
    </tr>
  <% end %>
</table>

<p><%= link_to "New Quotation", new_user_quotation_path(@user) %></p>

I've googled this extensively and can't figure out what's wrong with my code. Thanks!

One thing I noticed is it looks like you're mixing methodologies for looping over collections in ruby. That should work if you remove the for in the line <% for @quotations.each do |quotation| %> <% for @quotations.each do |quotation| %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM