如何删除设计路线以进行注册? [英] How do I remove the Devise route to sign up?

查看:26
本文介绍了如何删除设计路线以进行注册?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Rails 3 应用程序中使用 Devise,但在这种情况下,用户必须由现有用户创建,该用户决定他/她将拥有哪些权限.

I'm using Devise in a Rails 3 app, but in this case, a user must be created by an existing user, who determines what permissions he/she will have.

正因为如此,我想要:

  • 移除用户注册路径.
  • 仍然允许用户编辑他们的个人资料(更改电子邮件地址和密码)他们注册后
  • To remove the route for users to sign up.
  • To still allow users to edit their profiles (change email address and password) after they have signed up

我该怎么做?

目前,我通过在 devise_for :users 之前放置以下内容来有效地删除这条路线:

Currently, I'm effectively removing this route by placing the following before devise_for :users:

match 'users/sign_up' => redirect('/404.html')

这行得通,但我想还有更好的方法,对吧?

That works, but I imagine there's a better way, right?

正如 Benoit Garret 所说,就我而言,最好的解决方案是跳过大量创建注册路由,而只创建我真正想要的路由.

As Benoit Garret said, the best solution in my case is to skip creating the registrations routes en masse and just create the ones I actually want.

为此,我首先运行 rake routes,然后使用输出重新创建我想要的.最终结果是这样的:

To do that, I first ran rake routes, then used the output to re-create the ones I wanted. The end result was this:

devise_for :users, :skip => [:registrations] 
as :user do
  get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
  put 'users' => 'devise/registrations#update', :as => 'user_registration'
end

注意:

  • 我的 User 模型中仍然有 :registerable
  • devise/registrations 处理更新电子邮件和密码
  • 更新其他用户属性 - 权限等 - 由不同的控制器处理
  • I still have :registerable in my User model
  • devise/registrations handles updating email and password
  • Updating other user attributes - permissions, etc - is handled by a different controller

删除默认设计路径的路由;即:

Remove the route for the default Devise paths; i.e.:

devise_for :users, path_names: {
  sign_up: ''
}

推荐答案

我也试过这样做,但是 devise google group 上的一个帖子劝我不要寻找真正干净的解决方案.

I tried to do this as well, but a thread on the devise google group dissuaded me from searching for a really clean solution.

我会引用 José Valim(Devise 维护者)的话:

I'll quote José Valim (the Devise maintainer) :

没有直接的选择.您可以提供补丁或使用 :skip => :registerable 并仅添加您想要的路线.

There isn't a straight-forward option. You can either provide a patch or use :skip => :registerable and add only the routes you want.

原来的问题是:

有什么好的方法可以删除特定的路由(delete route)来自 Rails?

Is there any good way to remove a specific route (the delete route) from Rails?

这篇关于如何删除设计路线以进行注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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