使用自定义创建覆盖'Devise :: RegistrationsController'会产生NoMethodError

时间:2013-12-11 00:05:45

标签: ruby-on-rails devise analytics

如果我以错误的方式解决这个问题,请告诉我。我正在尝试向create方法中的用户添加一些自定义属性,并在保存用户时调用我的 Analytics 方法。

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

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

此创建方法中唯一不同的是,我在保存并运行Google Analytics之前添加 referral_code public_id

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

当我创建一个用户时,我正在

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

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

1 个答案:

答案 0 :(得分:3)

我想通了,我正在使用Devise 3.1.1版(锁定依赖项),看起来像 is_flashing_format?上个月在3.2.0中添加了。

我将控制器中的方法改为 is_navigational_format?,一切都很好!

相关问题