davidb
davidb

Reputation: 8954

How to overwrite :path_names for custom routes

I've implemented RESTFUL routes in english but the application is for german users so the routes should be renamed to german. I did this using the :path_names option and for the CRUD routes but this doesnt work for the routes I created on my own. For example the model SingleBudget has an action that removes specific objects from a n..n association. In my routes.rbit looks like this:

resources :single_budgets, :path => 'einzelbudgets', :path_names => { :new => 'neu', :edit => 'aendern', :remove => 'entfernen' } do
     collection do
          get ':id/remove' => "single_budgets#remove", :as => :remove
     end
end

It works for the new and edit action but not for the remove action. Does anybody have an idea how to fix it?

Upvotes: 0

Views: 497

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124469

The :path_names parameter will only affect the built-in CRUD actions. For your custom actions, just call it what you want right in the get parameter:

get ':id/entfernen' => "single_budgets#remove", :as => :remove

This will give you a remove_single_budgets path that will point to /single_budgets/:id/entfernen, which will execute the remove method in your controller.

Upvotes: 2

Related Questions