【问题标题】:ActiveRecord::ConnectionNotEstablished error when using has_and_belongs_to_many使用 has_and_belongs_to_many 时出现 ActiveRecord::ConnectionNotEstablished 错误
【发布时间】:2011-06-27 22:59:13
【问题描述】:

我遇到了 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​​ 中的活动记录不熟悉,因此我们将不胜感激

【问题讨论】:

    标签: ruby activerecord associations has-and-belongs-to-many


    【解决方案1】:

    您以这种方式连接到数据库有什么原因吗? 最好的方法是通过 database.yml。 http://wiki.rubyonrails.org/database-support/mysql#databaseyml_example

    [编辑] 对于 sqlite:http://wiki.rubyonrails.org/database-support/sqlite#databaseyml_example

    【讨论】:

    • 没有特别的原因。使用配置文件当然更好。我添加了配置文件的用法,但是仍然不能解决我的问题。我仍然遇到同样的错误。
    猜你喜欢
    • 2022-11-01
    • 2012-04-05
    • 1970-01-01
    • 2014-09-11
    • 2011-12-07
    • 1970-01-01
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多