How can I rename a Rails controller using a route?

I have a controller in a Rails 3 application called "my_store". I would like to be able to use this controller as is, with the exception of replacing "my_store" in the entire URL with a different name. I do not want to rename the controller file and all links to it. Is there an easy way to do this with just a routing instruction?

+3
source share
3 answers

If you use RESTful routes:

resources :another_name, :controller => "my_store"

Otherwise:

match "another_name" => "my_store"
+5
source

If your routes are RESTful, it's pretty simple.

resources :photos, :controller => "images"

, Rails Rails.

+4

Refresh , the other guys are correct to replace all the links that you would change the name of the resources and the corresponding controller in routes.rb! My answer is only useful for specifying a specific route.

Yup, you will do this in yours routes.rb, using the option :asto specify

Example:

match 'exit' => 'sessions#destroy', :as => :logout

source

0
source

All Articles