【发布时间】:2016-02-18 21:03:19
【问题描述】:
我需要从外部数据库(不是主要数据库)获取一些数据。所以我在 database.yml 中添加了一个连接条目。
external_reporting_table:
adapter: mysql2
encoding: utf8
database: reporting_db
host: localhost
username: root
password: password
我还创建了一个类来解决它,external_reporting_db.rb
class ExternalReportingDB < ActiveRecord::Base
self.abstract_class = true
establish_connection :external_reporting_table
end
我有这个模型,我需要从外部数据库 custom_report.rb 获取数据
class CustomReport < ExternalReportingDB
def self.shop_data_collection_abstract(batch_selections)
p "Here I need to get multiple data from external db's tables."
end
end
我应该怎么做才能从 custom_report.rb 中的外部数据库访问表?
【问题讨论】:
标签: mysql ruby-on-rails ruby ruby-on-rails-3