I thought I was following this RoR tutorial to a T, but apparently not. They instructed that we write this code into apps/views/index.html.erb
<h1>Listing posts</h1>
<table>
<tr>
<th>Name </th>
<th>Title </th>
<th>Content </th>
</tr>
<% for post in @posts %>
<tr>
<td><%=h post.name %></td>
<td><%=h post.title %></td>
<td><%=h post.content %></td>
<td><%= link_to'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post,
:confirm => 'Are you sure?',
:method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<% link_to 'New Post', new_post_path %>
It kicks back an error around line ten, but I’m not too clear on what the exact issue is. Can someone shine some light on the situation for me?
The error is
syntax error, unexpected ')', expecting kDO_COND or ':' or '\n' or ';'
....concat(( for post in @posts ).to_s); @output_buffer.concat ...
So long as
@postsis a collection of objects (presumablyPostobjects) that have attributesnametitleandcontent, and you have standard RESTful routes generated for the resource,your view is fine. Look at your controller.EDIT: the for…in syntax requires a do.
for post in @posts do…So the error was helpful — the bit about
KDO…