Renaming resources in Rails

If you’ve got a long model name and it’s ruining your URL paths and making them look terrible you can modify your config/routes.rb file to rename the path and helper routes of the model. The slash is in there to prevent WordPress changing the owners into a smiley face, thanks WordPress.

resources :gyms do
  resources :\owners
  resources :lessons do
   resources :student_lessons, path: "class", as: "class"
  end
end

About Nick

Melbourne based web developer that loves building front-end systems with anything from vanilla JS to React. Infosec student and active learner. Subscribe to the blog

www ·

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.