使用自定义创建覆盖“Devise::RegistrationsController"会导致 NoMethodError [英] Overwriting 'Devise::RegistrationsController' with custom create gives NoMethodError

查看:14
本文介绍了使用自定义创建覆盖“Devise::RegistrationsController"会导致 NoMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我以错误的方式处理此问题,请告诉我.我正在尝试在 create 方法中向 User 添加几个自定义属性,并在保存用户时调用我的 Analytics 方法.

Please let me know if I'm going about this the wrong way. I'm trying to add a couple custom attributes to a User in the create method as well as call my Analytics method if the user is saved.

我定义了一个新的控制器:

I defined a new controller:

class RegistrationsController < Devise::RegistrationsController


  def create
    build_resource(sign_up_params)

    resource.public_id = Utilities::generate_code
    resource.referral_code = Utilities::generate_code
    if resource.save

      Analytics.identify(
          user_id: resource.id.to_s,
          traits: { email: resource.email })

      yield resource if block_given?
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_flashing_format?
        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}" if     is_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
  end
end

此创建方法中唯一不同的是,我在保存之前添加了 referral_codepublic_id,之后再运行 Analytics.

The only thing different in this create method is that I'm adding referral_code and public_id before the save and running Analytics after.

      Analytics.identify(
      user_id: resource.id.to_s,
      traits: { email: resource.email })

当我创建一个用户时

undefined method `is_flashing_format?' for #<RegistrationsController:0x007fdba130d9a8>

我不明白为什么这个方法没有被继承.这甚至是修改设计或添加属性/添加分析的正确方法吗?

I don't understand why this method isn't being inherited. Is this even the proper way to modify devise or to add attributes/add analytics?

推荐答案

我想通了,我使用的是 Devise 版本 3.1.1(已锁定依赖项),它看起来像 is_flashing_format?上个月在 3.2.0 中添加.

I figured it out, I'm using Devise version 3.1.1 (locked for dependencies), it looks like is_flashing_format? was added last month in 3.2.0.

我将控制器中的方法更改为 is_navigational_format?,一切正常!

I changed the method in my controller to is_navigational_format? and all is well!

这篇关于使用自定义创建覆盖“Devise::RegistrationsController"会导致 NoMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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