Tommy
Tommy

Reputation: 1

Replacing / retrieving table from another database connection inside a model within Rails

Let's say I'm within a rails project in some model named Apple.

I'm going to switch databases to another server so I'll call: ActiveRecord::Base.establish_connection()

I want to access the table 'Banana' in this particular database. I can see that the table exists by calling table_exists?

However, I'm not sure how to access the table... I want to just be able to do something like Banana.find(:all)

How should I work this out?

Upvotes: 0

Views: 189

Answers (1)

hade
hade

Reputation: 1715

Have you tried connection_ninja gem? Pretty handy for multi-db connections:

https://github.com/cherring/connection_ninja

Upvotes: 1

Related Questions