New Rails app/old database - how to make them work together?

Hi guys - I have been searching and searching but I am just so confused. Here is my situation:

I am working on a front-end to an existing database. It's strictly lookup, no create/update/drop - just trying to get data out in a pretty way. I was hoping to do this in RoR as a learning exercise, and as a first step towards moving our web-apps to a more standard platform (right now they are a jumble of php, javascript, etc)

Here's my big problem:

Because of the way our db is structured, I can't make a read-only user account (this is stupid, I know, but unfortunately our dbadmin won't budge) - so I am concerned that if I make a migration, I might end up changing the db structure and affecting other users. I need a way to access the database that won't allow RoR to make any db changes at all - just the R part of crud...

Here's my smaller problem:

I want to acccess several databases at once - some of my data is on a MSSQL server, some on a MySQL server...

Am I barking up the wrong tree with RoR? This was easy (but MESSY) to do in php, but I'd really like to be using RoR as it seems like the way things are moving...

You should be able to make a SQL server "View" that is read only. and Mysql also supports views http://www.databasejournal.com/features/mysql/article.php/3399581

To talk to two database in ROR go here

http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases

good luck

Charles Bandes wrote:

Just generate models without migrations

Let’s say you have two tables like this:

widget

widget_id (int)

widget_name(varchar(50)

category_id

category

category_id (int)

category_name(varchar(50)

Generate models in rails:

ruby script/generate model Widget–skip-migration

ruby script/generate model Category --skip-migration

Open up /app/models/widget.rb and make it look like this:

class Widget < ActiveRecord::Base

set_table_name “widget”

set_primary_key “widget_id”

belongs_to :category

end

Now open up /app/models/category.rb and make it look like this:

class Widget < ActiveRecord::Base

set_table_name “category”

set_primary_key “category_id”

has_many :widgets

end

That should take care of the two biggest issues - id and table names. Other things to watch out for are field names. If you have field names with spaces, dashes, or other characters, life gets much more difficult.

Connecting to multiple databases can be done many ways. You have to decide how that’s going to work. Another poster already gave the wiki link, but here it is again: http://wiki.rubyonrails.org/rails/pages/HowtoUseMultipleDatabases

Brian Hogan wrote:

Just generate models without migrations

That looks like exactly what I want to do! Thank you :slight_smile:

Maybe I was looking in the wrong place, but none of my books/tutorials mentioned that this was a possibility.