如何使用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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...