ruby on rails - Efficient way to pull data from second database? -


we have primary database of our app resides.

but there's second database (updated external source), i'd able connect can pull data it. don't need write anything...just read.

it has 1 table i'm pulling from.

i need like:

otherdatabase.articles.where(id > 1000) 

and that's it.

so how can in rails (running 3.2.13)?

for simple scenarios, rails can support without gems; define database in database.yml:

other_db:   adapter: mysql2   encoding: utf8   database: other_db   username: user   password: passwd   host: 1.2.3.4   port: 3306 

then in model want use other database add:

class article < activerecord::base   establish_connection(:other_db)   self.table_name = 'other_db.articles' end 

and can perform query:

article.where("id > 1000") 

=)


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -