如何解决如何使用dev编辑create registrations_controller操作?
我正在制作一个简单的应用程序,该应用程序具有传统的用户模型,也具有患者模型。我希望用户自动成为注册患者。
我已经设法遵循说明here,并且可以看到文件window.top=window;
window.opener=window;
,但是我不确定要添加什么内容。
我从here粘贴了现有的devise创建代码
users/registations_controller.rb
,我也想添加功能来做到这一点:
def create
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message! :notice,:signed_up
sign_up(resource_name,resource)
respond_with resource,location: after_sign_up_path_for(resource)
else
set_flash_message! :notice,:"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource,location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
但是我不知道该怎么做? (我是否只需添加代码并将“用户”替换为“资源”?)
解决方法
您可以通过添加这样的块代码来完成此操作,而不是复制Devise代码
class YourController < Devise::RegistrationsController
def create
super do |user|
@patient = user.build_patient
@patient.save
end
end
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。