Written by Sean Behan on Sun Jun 17th 2012

Renaming routes in Rails 2.* is straight forward. It goes something like this.

## config/routes.rb
map.resources :users, :as => :members
This will give you users_path and form_for(User.new) helpers, for instance, mapping the url to /members instead of /users while using the users_controller.rb class.

In Rails 3.*, this is still possible. It is accomplished differently. In my opinion, it seems a little less elegant.

# config/routes.rb
resources :members, :as => :users, :controller => :users
# app/views/**/*.erb
link_to "Members", users_path
form_for User.new do |f|
# Rake routes
       users GET    /members(.:format)           {:controller=>"users", :action=>"index"}
       users POST   /members(.:format)           {:controller=>"users", :action=>"create"}
    new_user GET    /members/new(.:format)       {:controller=>"users", :action=>"new"}
   edit_user GET    /members/:id/edit(.:format)  {:controller=>"users", :action=>"edit"}
        user GET    /members/:id(.:format)       {:controller=>"users", :action=>"show"}
        user PUT    /members/:id(.:format)       {:controller=>"users", :action=>"update"}
        user DELETE /members/:id(.:format)       {:controller=>"users", :action=>"destroy"}
Your resource is "members" and you are overriding the name (using :as=>"users") however, you still have to specify the controller.

http://pastie.org/1154956


Tagged with..
#edge #rails 3 #routes #tips #Ruby on Rails

Just finishing up brewing up some fresh ground comments...