[英]Rails Index.html.erb misbehaving
我以为我正在将此RoR教程跟踪为T,但显然不是。 他们指示我们将这段代码写入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 %>
它会在第10行附近引发错误,但我不清楚确切的问题是什么。 有人可以为我介绍一下情况吗?
错误是
syntax error, unexpected ')', expecting kDO_COND or ':' or '\n' or ';'
....concat(( for post in @posts ).to_s); @output_buffer.concat ...
只要@posts
是具有name
属性title
和content
的对象(可能是Post
对象)的集合,并且您具有为该资源生成的标准RESTful路由,
您的视图就可以了。
看你的控制器。
编辑: for ... in语法中需要执行。 for post in @posts do
...
所以这个错误很有帮助-关于KDO
的一点...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.