Quick Tip: Override Rails Generated URLs
By default Ruby on Rails resources use the controller name for the URL. For example:
map.resources :time_entries
would yield the following URLs
What if you want them to be something else entirely? I guess you could rename your controller, update your routes.rb file and everywhere you use a URL helper… or, just use the “as” modifier!
map.resources :time_entries, :as => :time
now yields the following URLs
All of your existing uses of the URL helpers can remain the same and it will generate all URLs correctly. Quick, simple and painless!
References
More of my rantings
These might also interest you
- Outlook Tip (Brainfuel)
- BrainFuel Tip: Use the Sharpen Filter (Brainfuel)
- abcdefghijklmnopqrstuvwxyz (Brainfuel)








Nice tip. Huge time saver and allows for more descriptive models on the backend whilst keeping a simpleton interface. Cheers.
March 15th, 2010 at 5:41 pm