0

我降到10.43没有错误,但是在尝试创建微博后出现以下错误。教程说这会发生,我需要去为@feed_items 输入一个空白数组。尽管进行了上述更改,但我仍然遇到两个错误。提前致谢。

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

主页.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 %>
4

1 回答 1

0

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

于 2013-05-08T15:24:56.840 回答