我为嵌套资源No route matches
操作一直收到#create
错误。这是我得到的:
路线:
...
resources :users, only: [:show, :create] do
resources :filters, only: [:new,:create]
end
...
控制器规范:
...
context 'with valid attributes' do
it "creates new Filter" do
expect{
post :create, {:filter => attributes_for(:filter)}
}.to change(Filter, :count).by(1)
end
...
错误:
No route matches {:action=>"create", :controller=>"filters", :filter=>{[long filter hash]}
答案 0 :(得分:0)
因为它是嵌套的,所以还需要包含过滤器所属的父对象的ID。
post :create, user_id: <some_user_id>, {:filter => attributes_for(:filter)}