How do I work with a LEGACY database in Rails? -


i'm working on rails web site profiles stock mutual funds , etfs. have separate ruby script runs nightly , populates postgres database data on these mutual funds , etfs.

chapter 6 of rails tutorial isn't quite i'm looking for. differences between i'm trying , chapter 6 of rails tutorial are: 1. in rails site, there no need create database, because has been populated. don't think need use "rails generate" or "rake db:migrate". (or wrong?) 2. rails site reads data , not add, delete, or edit data.

you don't have create migrations. create models. if database table not match model name, can use set_table_name older versions of rails or self.table_name = 'table_name' newer versions. if don't use rails standard foreign keys , primary keys, you'll have specify well.

for example:

# assuming newer versions of rails (3.2+, believe)  class etf < activerecord::base   self.primary_key = 'legacy_id'   self.table_name = 'legacy_etfs'   has_many :closing_prices, foreign_key: 'legacy_etf_id' end  class closingprice < activerecord::base   self.primary_key = 'legacy_id'   self.table_name = 'legacy_closing_prices'   belongs_to :etf, foreign_key: 'legacy_etf_id' end 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -