Alias a route in Rails

Once in a while, I want a route but don’t want to change the controller name or any actual filenames. Route alias to the rescue. If I have a controller called ‘children’ but want a route called ‘kids’ so I can have a url like /kids/1234 then I would add this to my routes file:

resources :children, path: 'kids'

The only caveat is that your route helpers should still refer to the resource, so children_path(), not kids_path().

Related Posts with Thumbnails

Leave a Reply

Your email address will not be published. Required fields are marked *