我找不到错误,这让我发疯

时间:2016-03-24 23:47:43

标签: ruby-on-rails syntax views

这是index.html.erb

Post#index

我收到此错误:

/home/ubuntu/workspace/app/views/posts/index.html.erb:34: syntax error, unexpected '\n', expecting &. or :: or '[' or '.'

请帮忙!

<div class="title">

        <h1>All Posts</h1>
    </div>
    <div id="post_list">
        <% for @posts.each do |p| %>
            <div class="post_title">
                <h2><%= p.date.strftime("%Y%m%d") %></h2>
            </div>
            <div class="post_type">
                <h3><%= p.type %></h3>
            </div>
            <div class="post_content">
                <p><%= p.content %></p>
            </div>
                <% unless p.is_cited='false' %>
                    <div class="post_citation">
                        <p><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%= p.citation %></i></p>
                    </div>
                <% end %>
                </br>
                <div class="button">
                    <div class="action_buttons">
                        <div class="show">
                            <%= link_to 'Show', @post %>  
                        </div>
                        <div class="edit">
                            <%= link_to 'Edit', edit_post_path %>
                        </div>
                        <div class="delete">
                            <%= link_to 'Delete', post_path(@post), data: {confirm: "Are you sure?"}, :method => :delete %>
                        </div>
                    </div>
                </div> 
            <% end %>
    </div>

2 个答案:

答案 0 :(得分:1)

而不是以下内容:

<% for @posts.each do |p| %>

尝试:

<% @posts.each do |p| %>

答案 1 :(得分:0)

不确定这是否是导致问题的原因,但您在每个区块内引用@post。尝试更改

<%= link_to 'Show', @post %>

<%= link_to 'Show', p %>

并更改

<%= link_to 'Delete', post_path(@post), data: {confirm: "Are you sure?"}, :method => :delete %>

<%= link_to 'Delete', post_path(p), data: {confirm: "Are you sure?"}, :method => :delete %>