Last Updated: February 25, 2016
·
5.714K
· wjonthomas

Easily rename all routes for a Rails REST resource

I needed to generate a scaffold in Rails, but the name I wanted to call it was a Rails protected word. :( So, I called it something else and just figured I'd rewrite all my named routes so the URL would still appear to use the name I originally wanted to use. I'm still a Rails noobie, so I thought I'd share the quick tip I learned on renaming all routes for a single REST resource in one line:

resources :posts, :path => "entries"

That will turn this (and every other path for posts) from something like this:

posts GET    /posts(.:format)          posts#index

into this:

entries GET    /entries(.:format)          posts#index

Simple!