Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails教程10.3.3 feed_项目失败测试_Ruby On Rails_Rspec_Railstutorial.org - Fatal编程技术网

Ruby on rails rails教程10.3.3 feed_项目失败测试

Ruby on rails rails教程10.3.3 feed_项目失败测试,ruby-on-rails,rspec,railstutorial.org,Ruby On Rails,Rspec,Railstutorial.org,我开始认真考虑,没有错误,但是在尝试创建micropost之后出现了以下错误。教程说这会发生,我需要为@feed_项目输入一个空白数组。尽管做了上述修改,我仍然犯了两个错误。提前谢谢 Failures: 1) Static pages Home page for signed_in users should render the user's feed Failure/Error: visit root_path ActionView::Template::Error:

我开始认真考虑,没有错误,但是在尝试创建micropost之后出现了以下错误。教程说这会发生,我需要为@feed_项目输入一个空白数组。尽管做了上述修改,我仍然犯了两个错误。提前谢谢

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
故障:
1) 已登录用户的静态页面主页应呈现用户的提要
失败/错误:访问根目录路径
ActionView::模板::错误:
缺少具有{:locale=>[:en],:formats=>[:html],:handlers=>[:erb,:builder,:coffee]}的部分共享/提要_项。搜索:
*“/Users/patrick/rails\u projects/sample\u app/app/views”
#./app/views/shared/_-feed.html.erb:3:in`` app\u-views\u-shared\u-feed\u-html\u-erb\u 768030223365309889\u 70321791671740'
#./app/views/static\u pages/home.html.erb:13:in`` app\u views\u static\u pages\u home\u html\u erb\u 2533148950545762160\u 70321815481080'
#./spec/requests/static\u pages\u spec.rb:21:in'block(4级)in'
2) Micropost页面Micropost创建具有有效信息的页面应创建Micropost
失败/错误:期望{click_button“Post”}.更改(microspost,:count).by(1)
ActionView::模板::错误:
缺少具有{:locale=>[:en],:formats=>[:html],:handlers=>[:erb,:builder,:coffee]}的部分共享/提要_项。搜索:
*“/Users/patrick/rails\u projects/sample\u app/app/views”
#./app/views/shared/_-feed.html.erb:3:in`` app\u-views\u-shared\u-feed\u-html\u-erb\u 768030223365309889\u 70321791671740'
#./app/views/static\u pages/home.html.erb:13:in`` app\u views\u static\u pages\u home\u html\u erb\u 2533148950545762160\u 70321815481080'
#(评估):2:在“单击按钮”中
#./spec/requests/microspost_pages_spec.rb:29:in'block(5层)in'
#./spec/requests/microspost_pages_spec.rb:29:in'block(4层)in'
以11.87秒完成
103个示例,2个故障
失败的示例:
rspec./spec/requests/static_pages_spec.rb:24#登录用户的静态页面主页应呈现用户提要
rspec./spec/requests/micropost_pages_spec.rb:28#micropost pages micropost创建有效信息应创建一个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_控制器.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
class MicropostsController
_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 %>
    

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

    \u feed.item
    重命名为
    \u feed\u item
    。谢谢,这是一个简单的错误