使用 has_and_belongs_to_many 时 ActiveRecord::ConnectionNotEstablished 错误
我遇到 ActiveRecord::ConnectionNotEstablished 错误。
我有以下代码,
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
我是 ruby 中的活动记录新手,因此我们将不胜感激
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您以这种方式连接到数据库有什么原因吗?
最好的方法是通过database.yml。
http://wiki.rubyonrails.org/database-support/mysql#databaseyml_example
[编辑]
对于 sqlite: http://wiki.rubyonrails.org/database-support/sqlite#databaseyml_example< /a>
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