Railscasts #71:尝试在 post 方法中传递参数时出现路由错误
我正在使用 RSpec-2 来测试我的控制器,但我看到了奇怪的行为。 本质上,我所做的与 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[:deliverable].title.should == "Some Deliverable"
end
end
end
end
结果是以下错误:
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"}
显然 :deliverable
不应成为路由的一部分,而应写入 params
中。我的问题始于不确定调用哪个 post
方法。
我的 Gemfile.lock 可以在此处找到。
EDIT
我的routes.rb可以在这里找到。
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[:deliverable].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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有时,激发想法是件好事:我的问题是我处于嵌套路线中,基本上执行以下操作。
错误消息让我很困惑,真正的问题是我没有提供
project_id
。我通过这样做而不是
谢谢你,哈马尔!
Sometimes it is good to bounce off ideas: My problem was that I am in a nested route basically doing the following.
The error message threw me off, the real problem was that I did not provide a
project_id
. I fixed it by doinginstead of
Thank you, hammar!