我当前正在构建一个Rails引擎,我的应用程序中有两个数据库。我已经按照本教程https://www.thegreatcodeadventure.com/managing-multiple-databases-in-a-single-rails-application/中的建议完成了对数据库的配置 所以我有以下
在主应用程序中
models / insurance_db_base.rb
class InsuranceDbBase < ActiveRecord::Base
self.abstract_class = true
establish_connection INSURANCE_DB
end
和我的Rails引擎
models / product_type.rb
module Insurance
class ProductType < InsuranceDbBase
has_many :products
has_many :faqs
accepts_nested_attributes_for :faqs, allow_destroy: true, reject_if: :reject_fields
def reject_fields(attributes)
attributes['question'].blank?
attributes['answer'].blank?
end
validates :name, presence: true
end
end
但是当我运行类似ProductType.first
的查询时,我收到一条错误消息
cannot find insurance_product_types
。
因此,它似乎在数据库表的前面加上了我的引擎的名称。我怎么不允许这种情况发生?
谢谢