Posted almost 6 years ago. Visible to the public.

How to fix routing error when using concerns in Rails up to 3.2.22.1

tl;dr

  • Don't write resources :people, :concerns => :trashable

  • Write

    Copy
    resources :people do concerns :trashable end

Why

Writing a controller spec I encountered this error:

Copy
Failure/Error: get :index ActionController::RoutingError: No route matches {:controller=>"people"}

caused by this route definition

Copy
resources :people, :concerns => :trashable

which renders strange routes:

Copy
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 …

Copy
resources :people do concerns :trashable end

… and now my routes are fine.

Flaky tests are tests that sometimes fail for no obvious reason. They are the plague of many end-to-end (E2E) test suites that automate the browser through tools like Capybara and Selenium.

Join our free training event and learn to fix any flaky test suite, even in large legacy applications.

Owner of this card:

Avatar
Martin Straub
Last edit:
almost 6 years ago
by Martin Straub
Keywords:
rspec
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Martin Straub to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more