Hartl Rails教程的第10章:无法回家渲染_feed.html.erb

时间:2013-10-23 17:32:01

标签: ruby-on-rails ruby

当我通过Hartl Rails教程时,我已经能够跳过大多数的冲击,但我无法弄清楚我在10.4左右做错了什么。我可以使用 /static_pages/home.html.erb

正确渲染所有内容
<% if signed_in? %>
<div class="row">
    <aside class="span4">
        <section>
            <%= render 'shared/user_info' %>
        </section>
        <section>
            <%= render 'shared/micropost_form' %>
        </section>
    </aside>
    </div>
<% else %>
<div class="center hero-unit">
    <h1>Welcome to The Gentle Introduction Resource</h1>
    <p>
        This is the home page for the
        <a href="http://www.weekendpublisher.com">The Gentle Introduction Resource</a>
        web app.
    </p>

    <%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %>
</div>
<br/>
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>

但是当我包含这段代码时:

<div class="span8">
        <h3>Micropost Feed</h3>
        <%= render 'shared/feed' %>
    </div>
它打破了。

完整 home.html.erb

<% if signed_in? %>
    <div class="row">
        <aside class="span4">
            <section>
                <%= render 'shared/user_info' %>
            </section>
            <section>
                <%= render 'shared/micropost_form' %>
            </section>
        </aside>
        <div class="span8">
            <h3>Micropost Feed</h3>
            <%= render 'shared/feed' %>
        </div>
    </div>
    <% else %>
    <div class="center hero-unit">
        <h1>Welcome to The Gentle Introduction Resource</h1>
        <p>
            This is the home page for the
            <a href="http://www.weekendpublisher.com">The Gentle Introduction Resource</a>
            web app.
        </p>

        <%= link_to "Sign up now!", signup_path, class: "btn btn-large btn-primary" %>
    </div>
    <br/>
    <%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>
<% end %>

Here is my _feed.html.erb:

    <% If @feed_items.any? %>
    <ol class="microposts">
        <%= render partial: 'shared/feed_item', collection: @feed_items %>
    </ol>
    <%= will_paginate @feed_items %>
    <% end %>

这是我的 _feed_item.html.erb

<li id="<%= feed_item.id %>">
<%= link_to gravatar_for(feed_item.user), feed_item.user %>
<span class="user">
    <%= link_to feed_item.user.name, feed_item.user %>
</span>
<span class="content"><%= feed_item.content %></span>
<span class="timestamp">
    Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
</span>
<% if current_user?(feed_item.user) %>
    <%= link_to "delete", feed_item, method: delete, 
    data: { confirm: "You sure?" },
    title: feed_item.content %>
<% end %>
</li>

提前抱歉我的标记,这是我的第一个堆栈溢出问题。

哦,这是我在尝试加载本地网站时遇到的错误:

Static_pages #home

中的SyntaxError

显示/ rails_projects/sample_appOct20_2013/app/views/shared/_feed.html.erb第7行引发:

/rails_projects/sample_appOct20_2013/app/views/shared/_feed.html.erb:7:语法错误,意外的keyword_ensure,期待$ end 提取的来源(第7行):

4:  </ol>
5:  <%= will_paginate @feed_items %>
6: <% end %>

模板包含跟踪:app / views / shared / _feed.html.erb,app / views / static_pages / home.html.erb

1 个答案:

答案 0 :(得分:0)

我认为它的首都是

应该是:

<% if @feed_items.any? %>
<ol class="microposts">
  <%= render partial: 'shared/feed_item', collection: @feed_items %>
</ol>
<%= will_paginate @feed_items %>
<% end %>

由于这种情况,它认为&lt;%end%&gt;标签不是必需的。它确实需要,但'If'(大写)与'if'(小写)不同。