【问题标题】:intercom-rails: set some custom data attribute specific in actionintercom-rails:设置一些特定于操作的自定义数据属性
【发布时间】:2015-12-09 20:01:15
【问题描述】:

我想用 intercom-rails gem 设置自定义数据属性。在UserController#sign_up 我有intercom_custom_data.user[:sign_up] = true 但没有创建变量。我在其他控制器(TruckController#edit)中尝试,如果它被创建。

user_controller.rb

class UserController < ApplicationController                                                                                                                                                                                                               
  skip_before_filter :check_admin
  skip_before_filter :authenticate_user!, except: [:recovery]
  skip_before_filter :verify_authenticity_token

  def sign_up
    ...
    if user.save
      puts current_user.inspect 
      # <User id: 11, username: "user", email: "user@email.com", encrypted_password: "aebvcbb5c..."
      intercom_custom_data.user[:sign_up] = true
    end
  end
end

truck_controller.rb

TruckController < ApplicationController
  def index
    puts current_user.inspect 
    # <User id: 11, username: "user", email: "user@email.com", encrypted_password: "aebvcbb5c..."
    intercom_custom_data.user[:sign_up] = true
  end
end

【问题讨论】:

    标签: ruby-on-rails intercom


    【解决方案1】:

    我会在我的用户模型中添加一个字段,signed_up,这样您就可以随意更改它。

    现在,转到 config/initializers 中的 intercom.rb 配置文件,并将自定义数据字段添加到您的用户模型:

    IntercomRails.config do |config|
      ...
      config.user.model = Proc.new { YourUserModelClass }
    
      config.user.custom_data = {
        :sign_up=> Proc.new { |user| user.signed_up }
      }
      ...
    end
    

    之后您应该会在 Intercom 中看到该字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多