簡體   English   中英

Ruby Gem“Databasedotcom”同樣的對象問題

[英]Ruby Gem “Databasedotcom” same object issue

我使用Ruby Gem“Databasedotcom”將Salesforce集成到Rails應用程序中,一切正常,但我現在面臨Rails應用程序和Salesforce中相同對象名稱的問題。

我在Rails應用程序中有一個User模型,User對象也在Salesforce中。 因此,當嘗試從Salesforce User對象獲取數據時,它始終返回Rails應用程序用戶對象。

這是我的代碼

client = Databasedotcom::Client.new
client.client_id      #=> foo
client.client_secret  #=> bar

client.authenticate :username => "foo@bar.com", :password => "ThePasswordTheSecurityToken"  #=> "the-oauth-token"

client.materialize("User");

@user = User.find_by_Id('005d0000001291x');

但上面的語句總是使用Rails中的User模型。

我想使用Salesforce User對象來獲取其數據。

謝謝你的幫助。

首先在這樣的模塊中包裝SF代碼:

module SF
  module Connection          
    def self.client
      @client = Databasedotcom::Client.new("config/salesforce.yml")
      @client.authenticate :username => SF_CONFIG['username'], :password => SF_CONFIG['password_with_token']
      @client
    end
  end
end

並創建初始化程序,您可以在其中指定要與sobject_module param一起使用的模塊:

配置/ salesforce.yml:

username: username
password_with_token: token
client_secret: secret
client_id: cliend_id
sobject_module : SF

將初始化程序添加到配置/初始化程序:

salesforce.rb:

SF_CONFIG = YAML.load_file('config/salesforce.yml') rescue nil

現在您可以在SF模塊中使用用戶,它將是SF用戶,而不是您的AR用戶。

而且我強烈建議您閱讀文檔,有很多方法可以幫助您使SF代碼更清晰: http//rubydoc.info/github/heroku/databasedotcom/master/frames

祝SF好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM