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

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

问题描述

我在 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:

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: ''
}

推荐答案

我也尝试这样做,但是 设计谷歌小组的一个帖子劝阻我不要寻找一个真正干净的解决方案.

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.

最初的问题是:

有没有什么好办法去除特定路由(删除路由)来自 Rails?

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

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

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