Douglas
Douglas

Reputation: 5349

How to customize (Rails) Devise routes ending with 'new', 'edit', and so on?

Here it is the devise part of my config/route.rb :

devise_for :admin_utilisateurs, :path_names => { :sign_up => 'enregistrer',
                                                 :sign_in => 'connexion',
                                                 :sign_out => 'deconnexion',
                                                 :password => 'mot_de_passe',
                                                 :unlock => 'deverouiller'},
                                :path => 'identification'

This result in the following rake routes :

        new_admin_utilisateur_session GET    /identification/connexion(.:format)             devise/sessions#new
            admin_utilisateur_session POST   /identification/connexion(.:format)             devise/sessions#create
    destroy_admin_utilisateur_session DELETE /identification/deconnexion(.:format)           devise/sessions#destroy
           admin_utilisateur_password POST   /identification/mot_de_passe(.:format)          devise/passwords#create
       new_admin_utilisateur_password GET    /identification/mot_de_passe/new(.:format)      devise/passwords#new
      edit_admin_utilisateur_password GET    /identification/mot_de_passe/edit(.:format)     devise/passwords#edit
                                      PUT    /identification/mot_de_passe(.:format)          devise/passwords#update
cancel_admin_utilisateur_registration GET    /identification/cancel(.:format)                devise/registrations#cancel
       admin_utilisateur_registration POST   /identification(.:format)                       devise/registrations#create
   new_admin_utilisateur_registration GET    /identification/enregistrer(.:format)           devise/registrations#new
  edit_admin_utilisateur_registration GET    /identification/edit(.:format)                  devise/registrations#edit
                                      PUT    /identification(.:format)                       devise/registrations#update
                                      DELETE /identification(.:format)                       devise/registrations#destroy
       admin_utilisateur_confirmation POST   /identification/confirmation(.:format)          devise/confirmations#create
   new_admin_utilisateur_confirmation GET    /identification/confirmation/new(.:format)      devise/confirmations#new
                                      GET    /identification/confirmation(.:format)          devise/confirmations#show
             admin_utilisateur_unlock POST   /identification/deverouiller(.:format)          devise/unlocks#create
         new_admin_utilisateur_unlock GET    /identification/deverouiller/new(.:format)      devise/unlocks#new
                                      GET    /identification/deverouiller(.:format)          devise/unlocks#show

How can I change ?, for instance, the route :

/identification/deverouiller/new

into

/identification/deverouiller/nouveau

If I add :new => 'nouveau' into the :path_names hash, that does'nt work.

Many thanks for help

Upvotes: 0

Views: 486

Answers (2)

Luc
Luc

Reputation: 153

One solution which does not require using an additional gem consists in using a scope with a path_names option:

scope path_names: { new: 'creer', edit: 'modifier' } do

   devise_for :users

end

See http://guides.rubyonrails.org/routing.html#overriding-the-new-and-edit-segments for more information.

Upvotes: 2

Prakash Murthy
Prakash Murthy

Reputation: 13067

Looks like rails-translate-routes gem could help with this. Check out the I18n Routes section in this blogpost by Fabio Akita : Minimal I18n with Rails 3.2 for details about how to use the gem - in conjunction with devise - to translate to full URL to native languages.

Upvotes: 1

Related Questions