【问题标题】:Hartl Tutorial Chapter 10: param micropost not foundHartl教程第10章:param micropost not found
【发布时间】:2014-03-05 01:49:43
【问题描述】:

我目前在本教程的清单 10.32 和 10.33 之间:http://ruby.railstutorial.org/chapters/user-microposts#sec-manipulating_microposts

我在运行测试时遇到了问题。输出如下:

Failures:

  1) Micropost pages micropost creation with invalid information should not create a micropost
     Failure/Error: expect { click_button "Post" }.not_to change(Micropost, :count)
     ActionController::ParameterMissing:
       param not found: micropost
     # ./app/controllers/microposts_controller.rb:23:in `micropost_params'
     # ./app/controllers/microposts_controller.rb:8:in `create'
     # ./spec/requests/micropost_pages_spec.rb:16:in `block (5 levels) in <top (required)>'
     # ./spec/requests/micropost_pages_spec.rb:16:in `block (4 levels) in <top (required)>'

  2) Micropost pages micropost creation with invalid information error messages 
     Failure/Error: before { click_button "Post" }
     ActionController::ParameterMissing:
       param not found: micropost
     # ./app/controllers/microposts_controller.rb:23:in `micropost_params'
     # ./app/controllers/microposts_controller.rb:8:in `create'
     # ./spec/requests/micropost_pages_spec.rb:20:in `block (5 levels) in <top (required)>'

  3) Micropost pages micropost creation with valid information should create a micropost
     Failure/Error: before { fill_in 'micropost_content', with: "Lorem ipsum" }
     Capybara::ElementNotFound:
       Unable to find field "micropost_content"
     # ./spec/requests/micropost_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

Finished in 0.56491 seconds
3 examples, 3 failures

Failed examples:

rspec ./spec/requests/micropost_pages_spec.rb:15 # Micropost pages micropost creation with invalid information should not create a micropost
rspec ./spec/requests/micropost_pages_spec.rb:21 # Micropost pages micropost creation with invalid information error messages 
rspec ./spec/requests/micropost_pages_spec.rb:28 # Micropost pages micropost creation with valid information should create a micropost

这是当前失败的测试:

require 'spec_helper'

describe "Micropost pages" do

    subject { page }

    let(:user) { FactoryGirl.create(:user) }
    before { sign_in user }

    describe "micropost creation" do
        before { visit root_path }

        describe "with invalid information" do

            it "should not create a micropost" do
                expect { click_button "Post" }.not_to change(Micropost, :count)
            end

            describe "error messages" do
                before { click_button "Post" }
                it { should have_content('error') }
            end
        end

        describe "with valid information" do

            before { fill_in 'micropost_content', with: "Lorem ipsum" }
            it "should create a micropost" do
                expect { click_button "Post" }.to change(Micropost, :count).by(1)
            end
        end
    end

end

这意味着@micropost 变量显然没有被设置,但它是在静态页面控制器中设置的。我检查了一段时间,确实发现了与教程的差异,但没有成功找到任何东西。

git 仓库在这里:https://github.com/afuhrtrumpet/sample_app/tree/user-microposts

有人看到这个问题吗?

【问题讨论】:

  • micropost_pages_spec.rb 现在存在于 github 存储库中。我也会把它包含在帖子中。

标签: ruby-on-rails ruby railstutorial.org


【解决方案1】:

问题在于此处缺少“=”符号:

<%= f.text_area :content, placeholder: "Compose new micropost..." %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多