2012-07-16 39 views
0

我正在使用Ruby Gem“Databasedotcom”将Salesforce集成到Rails应用程序中,并且所有工作都正常,但我现在在Rails应用程序和Salesforce中面临相同对象名称的问题。Ruby Gem“Databasedotcom”同一对象问题

我在我的Rails应用程序中有用户模型,用户对象也在Salesforce中。因此,当试图从Salesforce User对象获取数据时,它总是返回Rails应用程序User对象。

这里是我的代码

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

client.authenticate :username => "[email protected]", :password => "ThePasswordTheSecurityToken" #=> "the-oauth-token" 

client.materialize("User"); 

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

但上述说法始终使用Rails的用户模型。

我想使用Salesforce用户对象来获取其数据。

感谢您的任何帮助。

回答

2

起初,包你的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参数去使用初始化:

配置/ salesforce.yml:

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

将初始化器添加到配置/初始化程序中:

sa lesforce.rb:

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

现在你可以使用SF模块内的用户,它将是SF用户,而不是你AR一个。

同时,我强烈建议你阅读文档,也有相当多的方法,这将有助于你使你的SF代码更加清晰: http://rubydoc.info/github/heroku/databasedotcom/master/frames

祝SF!

+0

感谢您的回复,我会实施这一点,让你如果一切正常,谢谢 – 2012-07-16 06:14:47

+0

非常感谢。有用 – 2012-07-16 08:22:08