2013-05-02 103 views
0

我得到了10.43没有错误,但是在尝试创建微博后发生了以下错误。该教程说这会发生,我需要去为@feed_items输入一个空白数组。尽管做出了上述改变,但我仍然得到两个错误。提前致谢。rails教程10.3.3 feed_item失败测试

Failures: 

    1) Static pages Home page for signed_in users should render the user's feed 
    Failure/Error: visit root_path 
    ActionView::Template::Error: 
     Missing partial shared/feed_item with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: 
     * "/Users/patrick/rails_projects/sample_app/app/views" 
    # ./app/views/shared/_feed.html.erb:3:in `_app_views_shared__feed_html_erb__768030223365309889_70321791671740' 
    # ./app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb___2533148950545762160_70321815481080' 
    # ./spec/requests/static_pages_spec.rb:21:in `block (4 levels) in <top (required)>' 

    2) Micropost pages micropost creation with valid information should create a micropost 
    Failure/Error: expect { click_button "Post" }.to change(Micropost, :count).by(1) 
    ActionView::Template::Error: 
     Missing partial shared/feed_item with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: 
     * "/Users/patrick/rails_projects/sample_app/app/views" 
    # ./app/views/shared/_feed.html.erb:3:in `_app_views_shared__feed_html_erb__768030223365309889_70321791671740' 
    # ./app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb___2533148950545762160_70321815481080' 
    # (eval):2:in `click_button' 
    # ./spec/requests/micropost_pages_spec.rb:29:in `block (5 levels) in <top (required)>' 
    # ./spec/requests/micropost_pages_spec.rb:29:in `block (4 levels) in <top (required)>' 

Finished in 11.87 seconds 
103 examples, 2 failures 

Failed examples: 

rspec ./spec/requests/static_pages_spec.rb:24 # Static pages Home page for signed_in users should render the user's feed 
rspec ./spec/requests/micropost_pages_spec.rb:28 # Micropost pages micropost creation with valid information should create a micropost 

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 Sample App</h1> 

     <h2> 
      This is the home for the 
      <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
      sample application 
     </h2> 

     <%= link_to "Sign up now!", signup_path, 
         class: "btn btn-large btn-primary" %> 
    </div> 

    <%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %> 
<% end %> 

microposts_controller.rb

class MicropostsController < ApplicationController 
    before_filter :signed_in_user, only: [:create, :destroy] 

    def create 
    @micropost = current_user.microposts.build(params[:micropost]) 
    if @micropost.save 
     flash[:success] = "Micropost created!" 
     redirect_to root_url 
    else 
     @feed_items = [] 
     render 'static_pages/home' 
    end 
    end 

    def destroy 
    end 
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> 

_feed.html.erb

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

将_feed.item重命名为_feed_item。 – Sun 2013-05-02 13:34:45

+0

谢谢,这样一个简单的错误 – Patrick 2013-05-03 10:47:01

回答

0

在rails中,partials以下划线开头,扩展名(实际上有两个扩展名,如.html.erb)允许选择相应的渲染器。 由于@Sunxperous建议您需要重命名文件。