我是Ruby,Rails和一般編程的新手,所以請原諒我,如果問題很微不足道。 我有這樣的觀點:學習Ruby on Rails。語法問題
<h1>Listing products</h1>
<table>
<tr>
<th>\</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @products.each do |product| %>
<tr>
<td><%= product.\ %></td>
<td><%= link_to 'Show', product %></td>
<td><%= link_to 'Edit', edit_product_path(product) %></td>
<td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Product', new_product_path %>
當我嘗試訪問該鏈接http://localhost:3000/products
我收到一個錯誤:
SyntaxError in Products#index
Showing C:/Sites/depot/app/views/products/index.html.erb where line #13 raised:
C:/Sites/depot/app/views/products/index.html.erb:13: syntax error, unexpected $undefined
...tput_buffer.append= (product.\);@output_buffer.safe_concat...
... ^
C:/Sites/depot/app/views/products/index.html.erb:18: syntax error, unexpected keyword_end, expecting ')'
'); end
^
C:/Sites/depot/app/views/products/index.html.erb:25: syntax error, unexpected keyword_ensure, expecting ')'
C:/Sites/depot/app/views/products/index.html.erb:27: syntax error, unexpected keyword_end, expecting ')'
Extracted source (around line #13):
10:
11: <% @products.each do |product| %>
12: <tr>
13: <td><%= product.\ %></td>
14: <td><%= link_to 'Show', product %></td>
15: <td><%= link_to 'Edit', edit_product_path(product) %></td>
16: <td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Trace of template inclusion: app/views/products/index.html.erb
我只是按照一本書來學習Rails的一個例子,所以基本上我我沒有做任何事情來編寫這個觀點。 有人能指引我走向正確的方向嗎?
這是什麼'<%= product。\%>'?是''產品'的屬性嗎?看起來像你應該調用一些屬性而不是反斜槓 – 2013-04-24 08:28:28
你想要做什麼<% = product。\%>? – Abram 2013-04-24 08:28:43