gpt4 book ai didi

ruby-on-rails - 自定义 Devise 路径名

转载 作者:数据小太阳 更新时间:2023-10-29 08:57:35 34 4
gpt4 key购买 nike

我正在尝试自定义由 devise gem 创建的 url:

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

如何使用设计更改唯一 Controller 方法的路径名称(无需使用自定义 Controller 手动重写它们)?

最佳答案

来自documentation ,看起来您可以像往常一样使用 block 来更多地定义路由。

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

关于ruby-on-rails - 自定义 Devise 路径名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46898046/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com