0

I would like to create a Rails application that will access a Database (namely two different databases) and do some comparing. Then i went that data spit back out into the view for users to see.

This application will not create or save any data anywhere.

All i want is for user to pick a date and then get data from the databases based on this workflow.

I have been trying tableless models all morning, but i am a bit stuck.

For example, should i have my model still be able to access the database but not allow any create methods?

Any ideas?

1 Answers1

0

You can have rails working with different connections at each time and you can also have different connections customized for each model.

From the API:

Connection to multiple databases in different models

Connections are usually created through ActiveRecord::Base.establish_connection and retrieved by ActiveRecord::Base.connection. All classes inheriting from ActiveRecord::Base will use this connection. But you can also set a class-specific connection. For example, if Course is an ActiveRecord::Base, but resides in a different database, you can just say Course.establish_connection and Course and all of its subclasses will use this connection instead.

This feature is implemented by keeping a connection pool in ActiveRecord::Base that is a Hash indexed by the class. If a connection is requested, the retrieve_connection method will go up the class-hierarchy until a connection is found in the connection pool.

This answer will help you to do it in code.

Community
  • 1
  • 1
pedrofs
  • 612
  • 1
  • 6
  • 14