Rails 3 : route a resource to another name

20,934

Solution 1

You can add a new resource and specify foo as the controller:

resources :toto, :controller=>"foo"

This will point all the actions to "foo", but there is a gotcha. I think you will run into problems with the links on the page, if you are using foo_url or something like that. So you would have to figure out a way to create the URLs dymanically based on the controller in "request.path".

Solution 2

This will let you rename paths seen by the user but keep the original name of your controllers in the code:

scope(:path_names => { :new => "neu", :edit => "bearbeiten" }) do
  resources :categories, :path => "kategorien"
end

From the Ruby on Rails Guides

Solution 3

If I understand you correctly, you want to just use another path.

resources :foo, path: 'toto'

Now you will have:

GET /toto          foo#index
GET /toto/:id      foo#show
...
Share:
20,934

Related videos on Youtube

glmxndr
Author by

glmxndr

O}=<

Updated on July 09, 2022

Comments

  • glmxndr
    glmxndr almost 2 years

    I have a CRUD controller for a model.

    Doing resources :foo allows me to route on /foo/:id, etc. for calling actions.

    I want add a route for a translation of 'foo' in another language. Let's say 'toto'. So I want all the /toto/:id, etc., routes to act exactly like the /foo/:id, etc., routes.

    How may I achieve that?

  • FloatingRock
    FloatingRock over 9 years
    Any idea as to how we can get the views to load up from views/toto instead of views/foo?
  • Ruby
    Ruby almost 9 years
    resources :toto, :controller=>"foo", :path => "toto"