0

I am running into ActiveRecord::ConnectionNotEstablished error.

I have the following code

ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'users_vendors.db')

Class User < ActiveRecord::Base
   has_and_belongs_to_many :vendors
end

class Vendor < ActiveRecord::Base
   has_and_belongs_to_many :users
end

I am new to active records in ruby so any help would be appreciated

dmg
  • 608
  • 8
  • 15

1 Answers1

1

Is there any reason why you are connecting to the database in this fashion? The best way to do that is through a database.yml. http://wiki.rubyonrails.org/database-support/mysql#databaseyml_example

[Edit] For sqlite: http://wiki.rubyonrails.org/database-support/sqlite#databaseyml_example

brayne
  • 1,355
  • 2
  • 16
  • 27
  • There is no particular reason. Using a config file of course is better. I added usage of config file, however, that still does not solve my problem. I still get the same error. – dmg Jun 27 '11 at 23:24