扩展设备注册控制器 [英] Extending Devise Registration Controller
问题描述
我有一个用Devise设置的Accounts
模型. Devise使用一些属性(例如电子邮件,密码等),但是我还有其他一些属性.在注册时,我想以某种方式进行设置.
I have an Accounts
model set up with Devise. Devise uses a few attributes (such as email, password etc.) but I have a few other attributes that I made. On sign up, I'd like to set them up in a way.
如何扩展注册控制器?我了解我实际上需要创建一个新的控制器,如下所示:
How can I extend the registration controller? I understand that I need to actually create a new controller like this:
class AccountsController < Devise::RegistrationController
def create
super
end
end
我可以在super
之后添加代码吗?我认为为时已晚,因为资源已经被保存了.最好的方法是什么?
Can I just add my code right after super
? I think it would be too late as the resource would have already been saved. What's the best way to do this?
如果我要从头开始编写create,我怎么会知道我没有错过Devise所做的任何事情?
If I were to write create from scratch, how would I know that I didn't miss anything that Devise does?
谢谢
推荐答案
如果要从头开始重写控制器以实现完全控制,请从registration_controller.rb
If you want to rewrite the controller from scratch for full control, start with the registration_controller.rb Source Code and make your changes as necessary.
说出使用自定义控制器的设计就像更改路线一样简单:
Telling devise to use your custom controller is as simple as changing the route:
devise_for :users, :controllers => { :registrations => "users/custom_controller" }
这篇关于扩展设备注册控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!