Ruby on rails Rails Index.html.erb行为不正常
我以为我是在遵循RoR教程,但显然不是。他们指示我们将此代码写入Ruby on rails Rails Index.html.erb行为不正常,ruby-on-rails,ruby,Ruby On Rails,Ruby,我以为我是在遵循RoR教程,但显然不是。他们指示我们将此代码写入apps/views/index.html.erb <h1>Listing posts</h1> <table> <tr> <th>Name </th> <th>Title </th> <th>Content </th> </tr&g
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 %>
只要
@posts
是具有属性name
title
和content
的对象(可能是Post
对象)的集合,并且您有为资源生成的标准RESTful路由,您的视图就可以了。看看你的控制器
编辑:for…in语法需要do<代码>用于@posts do中的post
所以这个错误是有帮助的-
KDO
…这个错误没有帮助。我把它贴在上面了。
syntax error, unexpected ')', expecting kDO_COND or ':' or '\n' or ';'
....concat(( for post in @posts ).to_s); @output_buffer.concat ...