jeudi 18 février 2016

Rails - How to access tables from external Database

I need to get some data from external db(Not the primary one). So I added a connection entry in database.yml.

external_reporting_table:
  adapter: mysql2
  encoding: utf8
  database: reporting_db
  host: localhost
  username: root
  password: password

Also I've created a class to address it, external_reporting_db.rb

class ExternalReportingDB < ActiveRecord::Base
  self.abstract_class = true
  establish_connection :external_reporting_table
end

I've this model I need to get the data from external db, 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

What should I do to access a table from external db in custom_report.rb ?

Aucun commentaire:

Enregistrer un commentaire