I am trying to connect multiple database in ROR application.My database.yml is look like this in your database.yml file
development:
adapter: mysql
username: root
password:
database: example_development
private:
adapter: mysql
username: root
password:
database: example_private_development
It is possible to connect using establish_connection :private
My doubt is that how use rake db:create.I am not able get solution from google.
Please help me to clear it.
Try
And yes, it's possible to have multiple db connections in a Rails application.
This is what I did once, I have created two classes which inherit from
ActiveRecord::Base
and set the connections inside those classes.Then I inherited all my models in one of those classes instead of direct
ActiveRecord
Below is an example:
Then I have two models for both test1 and test2 databases:
Then I inherit my models according to database:
Thanks for reply.
we can migrate a model for particular DB, for example
db:migrate RAILS_ENV="portal_development"'
.And more change for establishing connection with DB.check the corrected below
Thanks sameera for your valuable reply.
cheers
Shamith c
Possibly use
active_delegate
? http://railslodge.com/plugins/595-active-delegate