繁体   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