views:

77

answers:

1

Not sure how to ask it so sorry if I mess up my terminology. In using jruby on rails, how would I query two (or more database) to serve back to the view page?

I have seen where I set up my database connection in database.yml and it works fine but I am now wondering how I move beyond this to hitting many databases with jdbc and puttting them in one webpage view.

My title is worded the way it is because I am used to a non-orm non-mvc way of doing things. For example, need to query somethingn in classic asp? Just create the object and emit html and your dataset for each database. Cumbersome but at least I know how to do it. Need to hit five databases in asp.net? Just have a control and in the code-behind bind it to the table adapter or do a sql query. Here, I'm just lost on how to do this.

How do I do query several databases, different ones (oracle, sql server, etc.) in Jruby on Rails with jdbc and put them all in one page? And do this the "right" way so that I don't end up with my jror application looking like classic asp.

EDIT: I think something like this might be what I am looking for, but I am not sure how to put both sets of data on the same page.

A: 

Put the query logic in the appropriate models (activerecord models for your main db tables, non-activerecord models for other sources of data). These should have intention revealing method names.

In the controller action query for the information your web page needs. Load these data into instance variables.

In the view, interact simply with the instance variables to display them using ERB. If you find logic in your views, you're doing it wrong and should refactor.

For multiple DBs, this may be of help http://tomayko.com/writings/rails-multiple-connections

Ben Hughes