开发者

Railscasts #71: Routing error when trying to pass parameters in post method

I am using RSpec-2 to test my controller and I am seeing weird behavior. Essentially I am doing the same as in Railscasts #71

describe DeliverablesController do
  describe "responding to POST create" do
    describe "with valid parameters" do
      it "should pass the params to the deliverable item" do
        post :create, :deliverable => {:title => "Some Deliverable"}
        assigns[:delive开发者_开发问答rable].title.should == "Some Deliverable"
      end
    end
  end
end

Which results in the following error:

  1) DeliverablesController responding to POST create with valid parameters should pass the params to the deliverable item
     Failure/Error: post :create, :deliverable => {:title => "Some Deliverable"}
     ActionController::RoutingError:
     No route matches {:deliverable=>{:title=>"Some Deliverable"}, :controller=>"deliverables", :action=>"create"}

Obviously :deliverable should not be part of the route but written into params. My problem starts with not being sure which post method is called.

My Gemfile.lock can be found here.


EDIT

And my routes.rb can be found here.


Sometimes it is good to bounce off ideas: My problem was that I am in a nested route basically doing the following.

resources :projects do
    resources :deliverables
end

The error message threw me off, the real problem was that I did not provide a project_id. I fixed it by doing

post :create, :project_id => 11, :deliverable => {:title => "Some Deliverable"}

instead of

post :create, :deliverable => {:title => "Some Deliverable"}

Thank you, hammar!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜