我正在尝试自定义设计gem创建的网址:
devise_for :users, path: '', path_names: {
sign_in: 'login',
sign_out: 'logout',
sign_up: 'signup',
password: 'forgot',
confirmation: 'activate',
invitation: 'invite'
}
这很有效。它创建了以下路径:
/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
但我希望实现这样的目标:
/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
如何使用devise更改唯一控制器方法的路径名(不用手动将它们与自定义控制器一起重写)?
答案 0 :(得分:2)
从documentation开始,您可以像往常一样使用块来更多地定义路线。
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