自定义设计路径名 [英] Customize Devise pathnames

查看:28
本文介绍了自定义设计路径名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义设计 gem 创建的网址:

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

这篇关于自定义设计路径名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆