如何删除Devise路线注册? [英] How do I remove the Devise route to sign up?
问题描述
我在Rails 3应用中使用Devise,但在这种情况下,用户必须由现有用户创建,用户可以确定他/她拥有的权限。
因此,我想要:
- 要删除用户注册的路由。
- 若要还允许用户修改他们的个人资料(更改电子邮件地址和密码) b $ b
我该怎么做?
目前,我通过放置以下之前 devise_for:users
:
match'users / sign_up' =>重定向('/ 404.html')
这是有效的,但我想像有更好的方法?
更新
正如Benoit Garret所说,我的案例中最好的解决方案是跳过创建注册路由大量的,只是创造我实际想要的。
为此,我首先运行 rake路由
,然后使用输出重新创建我想要的。最终的结果是:
devise_for:users,:skip => [:registration]
as:user do
get'users / edit'=> 'devise / registrations#edit',:as => 'edit_user_registration'
put'users'=> 'devise / registrations#update',:as => 'user_registration'
end
请注意:
- 我的
用户
模型中还有:可注册
-
设计/注册
处理更新电子邮件和密码 - 更新其他用户属性 - 权限等由不同的控制器处理
实际答案:
默认设计路径;即:
devise_for:users,path_names:{
sign_up:''
}
我也试图这样做,但设计谷歌组织上的一个线程劝我不寻求一个非常干净的解决方案。
我会引用JoséValim(Devise维护者):
前进选项。您可以提供补丁
或使用:skip =>:可注册,只添加所需的路由。
原来的问题是:
有没有什么好的方法从Rails中删除一个特定的路由(删除路由)
? p>
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.
Because of this, I want:
- 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
How can I do this?
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?
Update
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.
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
Note that:
- I still have
:registerable
in myUser
model devise/registrations
handles updating email and password- Updating other user attributes - permissions, etc - is handled by a different controller
Actual answer:
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.
I'll quote José Valim (the Devise maintainer) :
There isn't a straight-forward option. You can either provide a patch or use :skip => :registerable and add only the routes you want.
The original question was :
Is there any good way to remove a specific route (the delete route) from Rails?
这篇关于如何删除Devise路线注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!