+ Start a Discussion

NoMethodError: undefined method `connection=' ... rails app with activesalesforce (incl. unit tests)

Hi all,

I am a newbie to activesalesforce and I'm trying to get it running. I ran into the above error when I created a simple rails app and added a scaffold for 'Account' using:

script/generate scaffold account

so, I tried to run the unit tests and got the same error (Error details after env)

My env:

ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]

actionmailer (2.2.2,,, 2.0.2, 1.3.6, 1.3.3)
actionpack (2.2.2,,, 2.0.2, 1.13.6, 1.13.3)
actionwebservice (1.2.6, 1.2.3)
activerecord (2.2.2,,, 2.0.2, 1.15.6, 1.15.3)
activerecord-activesalesforce-adapter (2.0.0)
activeresource (2.2.2,,, 2.0.2)
activesupport (2.2.2,,, 2.0.2, 1.4.4, 1.4.2)

database config
adapter: activesalesforce
username: <removed>
password: <removed>

I've tried with and w/o URLs specified (https://test.salesforce.com doesn't work for me).

Error details:

The log shows
Starting test 'AsfUnitTestsBasicTest.test_add_notes_to_contact'
   Created one-to-one relationship 'master_record' from Contact to Contact using master_record_id
   Creating ActiveRecord stub for the referenced entity 'Account'

The exception is:
  1) Error:
NoMethodError: undefined method `connection=' for #<Class:0x19b0a90>
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1833:in `method_missing
tion_adapters/activesalesforce_adapter.rb:698:in `configure_active_record'
tion_adapters/activesalesforce_adapter.rb:672:in `each'
tion_adapters/activesalesforce_adapter.rb:672:in `configure_active_record'
tion_adapters/activesalesforce_adapter.rb:649:in `get_entity_def'
tion_adapters/activesalesforce_adapter.rb:764:in `lookup'
tion_adapters/activesalesforce_adapter.rb:717:in `columns'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1220:in `columns'
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2839:in `attributes_fro
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/locking/optimistic.rb:55:in `at
    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2279:in `initialize'
    unit/basic_test.rb:56:in `new'
    unit/basic_test.rb:56:in `setup'

Note that the above is essentially the same when I try to access the accounts listing from my rails app, with the expected variations in the backtrace

With the rails app, if I generate the model class for XXXX (using script/generate model XXXX) for the object referred to in the log statement "Creating ActiveRecord stub for the referenced entity 'XXXXX'", the code will proceed further and fail identically but refer to another entity. After enough model classes are generated (to satisfy all associations, I guess), the code does work. But I realized after more research that ASF should handle all that for me. Somehow it doesn't.

I know I'm missing something, but don't know what. Any help is greatly appreciated.


Message Edited by vijayn on 12-01-2008 03:20 PM
Well, after a lot of trial and error, I discovered that activesalesforce is not compatible with Rails 2.2.2. I reverted to Rails 2.1.2 and things worked like a charm.

By the way, I did discover that I got a different exception under a different circumstance.
andromeda-7:forceTest2 vijay$ script/console
Loading development environment (Rails 2.2.2)
>> Account
NameError: undefined local variable or method `tables' for #<ActiveRecord::ConnectionAdapters::SalesforceAdapter:0x211ce28>
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:24:in `table_exists?'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1214:in `table_exists?'
    from /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:1353:in `inspect'
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb:298:in `output_value'

Note that the 'Account' object has a generated model class. Don't know if this is related, but thought I'd put it out there in the hope that it will help those who do know :)

silent (e)silent (e)
I'd love to get a Rails 2.2 working version of ASF as well.  The inner workings that build all these relationships is a little beyond me right now, however.

vijay, I got the same NO METHOD error with rails 2.2.2 I uninstalled 2.2.2 and installed 2.1.2 and it fixed the problem. I found this patch for 2.2.2 http://timothynjones.wordpress.com/2008/12/03/patching-activesalesforce-for-rails-222/ I have not tried it but seems to address your problems.

Thanks Kyle.

I'd already applied that patch, but there are other issues (undefined method tables?) that still crop up :(



I recently upgraded my Rails to 2.3.2 and then applied this patch and it worked! I was able to add/edit Lead, Contact, Event, Account objects which I was not able to with Rails 2.2. As pointed in by earlier poster, everything had worked fine in Rails 2.1 but after upgrading all my apps to Rails 2.3.2 I  did not have the option to go back to Rails 2.1. So I am glad this worked out for me.


Here is my gem list FWIW:


$ gem list --local active


*** LOCAL GEMS ***


activerecord (2.3.2, 2.2.2, 2.1.0, 2.0.2, 1.15.5, 1.15.3)

activerecord-activesalesforce-adapter (2.0.0)

activeresource (2.3.2, 2.1.0, 2.0.2)

activesupport (2.3.3, 2.3.2, 2.2.2, 2.1.1, 2.1.0, 2.0.2, 1.4.4, 1.4.2)



Hope that helps :)


- Shashank 


dini need some help with adding a lead. if you can please give some code samples, i have successfully connected with username and passwrd, just want to add a lead into the system now



Thanks in advance :)