heroxav
heroxav

Reputation: 1467

Customize Devise pathnames

I am trying to customize the urls created by the devise gem:

devise_for :users, path: '', path_names: {
    sign_in: 'login',
    sign_out: 'logout',
    sign_up: 'signup',
    password: 'forgot',
    confirmation: 'activate',
    invitation: 'invite'
}

This works well. It creates the following routes:

/login -> sessions#new
/logout -> sessions#destroy
/signup -> registrations#new
/forgot/new -> passwords#new
/forgot/edit -> passwords#edit
/activate/new -> confirmations#new
/activate/show -> confirmations#show
/invite/new -> invitations#new
/invite/accept -> invitations#edit
/invite/remove -> invitations#destroy

But instead I want to achieve something like this:

/login -> sessions#new
/logout -> sessions#destroy
/signup -> registrations#new
/forgot -> passwords#new
/recover -> passwords#edit
/activate -> confirmations#new
/confirm -> confirmations#show
/invite -> invitations#new
/invite/accept -> invitations#edit
/invite/remove -> invitations#destroy

How can change the path names of the unique controller methods with devise (without manually rewriting them all together with a custom controller)?

Upvotes: 2

Views: 1995

Answers (1)

mindlis
mindlis

Reputation: 1677

From the documentation, it looks like you can use a block to more define the routes as you would normally.

devise_for :users, skip: [:sessions, ...]
as :user do
  get 'login', to: 'sessions#new', as: :new_user_session
  get 'logout', to: 'sessions#destroy', as: :destroy_user_session
  ...
end

Upvotes: 2

Related Questions