ActiveRecord reading existing db not as OMS
Posted 27 November 2013 - 12:44 PM
I think ActiveRecord is fantastic at what it is intended as an Object Management System, but I need to do a simple select from an existing table that is exposed by another system.
I only need read access to display a list of records that will never be modified via the rails app
Should I be shoe horning ActiveRecord into this role or is the another rail/ruby tool that is more appropriate for this task.
Posted 07 December 2013 - 09:32 AM
ActiveRecord is fine, it doesn't even really need shoe horning although you will need to create a database connection string in your database.yml file for the databse concerned.
The model just needs to set the table name property and set the connection string but this is not really the best approach.
There are better alternatives though. The table you are talking about must already exist as part of another app and you should really ask for an api to hook into using JSON, that way no mistakes can be made, the data can't accidently be updated and the people responsible for the maintenance of the data and the other app can retain complete control over what is presented to you.
This is more important than it may at first seem. If there is any work done at all in the other app or on that table, the fact that there is an api will make the maintainer give thought to providing a consistent recordset and fields to you.
Don't think it won't happen, I can guarantee it will and even if I am wrong you have piece of mind in knowing that you don't need to care about the other app, all you need to care about is a consistent api.
Rails handles JSON very well and there is nothing wrong with you creating a class that can take the JSON and present it to your views in a way that you need.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users