自定义Devise路径名 [英] Customize Devise pathnames
本文介绍了自定义Devise路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试自定义由devise宝石创建的URL:
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
如何通过devise更改唯一控制器方法的路径名(无需手动重写)都与自定义控制器一起使用?)
How can change the path names of the unique controller methods with devise (without manually rewriting them all together with a custom controller)?
推荐答案
来自文档,您似乎可以使用一个块来更详细地定义路线,
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
这篇关于自定义Devise路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文