2013-05-02 62 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建議您需要重命名文件。