开发者

ActiveRecord::ConnectionNotEstablished error when using has_and_belongs_to_many

开发者 https://www.devze.com 2023-03-15 23:50 出处:网络
I am running into ActiveRecord::ConnectionNotEstablished error. I have the following code ActiveRecord::Base.establish_connection(:adapter => \'sqlite3\', :database => \'users_vendors.db\')

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_开发者_JAVA百科belongs_to_many :users
end

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消