簡體   English   中英

Rails Index.html.erb行為異常

[英]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屬性titlecontent的對象(可能是Post對象)的集合,並且您具有為該資源生成的標准RESTful路由, 您的視圖就可以了。 看你的控制器。

編輯: for ... in語法中需要執行。 for post in @posts do ...

所以這個錯誤很有幫助-關於KDO的一點...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM