tl;dr
-
Don't write
resources :people, :concerns => :trashable
-
Write
resources :people do concerns :trashable end
Why
Writing a controller spec I encountered this error:
Failure/Error: get :index
ActionController::RoutingError:
No route matches {:controller=>"people"}
caused by this route definition
resources :people, :concerns => :trashable
which renders strange routes:
trash_person PUT /people/:id/trash(.:format) people#check {:concerns=>:trashable}
people GET /people(.:format) people#index {:concerns=>:trashable}
POST /people(.:format) people#create {:concerns=>:trashable}
new_person GET /people/new(.:format) people#new {:concerns=>:trashable}
edit_person GET /people/:id/edit(.:format) people#edit {:concerns=>:trashable}
person GET /people/:id(.:format) people#show {:concerns=>:trashable}
PUT /people/:id(.:format) people#update {:concerns=>:trashable}
DELETE /people/:id(.:format) people#destroy {:concerns=>:trashable}
Note the {:concerns=>:trashable}
at the end of each route.
The fix
… was to write the routes with another syntax …
resources :people do
concerns :trashable
end
… and now my routes are fine.
Posted by Martin Straub to makandra dev (2016-03-11 15:21)