|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Using existing database with Ruby on Rails
Hi guys I'm on the early stages on learning Ruby. I got a good collection of ebooks that I'm reading myself on my free time.
The thing is that I really don't have an idea on how to use an existing database filled with tables and data on ruby. Every guide, every article that I have or find on the internet is always creating a new one using the migration functions. But which are the steps for using an existing database on RoR? Thanks in advance. |
|
#2
|
||||
|
||||
|
The procedure is very simple.
1. Create a new rails project. 2. Edit your_project_name/config/database.yml and set up the connection parameters so that it connects to your existing database. 3. Type the following for each table in your existing database: Code:
script/generate model tablename and substitute tablename for each table in your database. This will create ruby objects to access the existing tables in your database. As you can see, there's nothing complicated about the procedure.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
Quote:
Awesome thanks !!! |
|
#4
|
||||
|
||||
|
Also, to take advantage of rails' built in features, read *UP* on ActiveRecord. There are a tremendous number of conventions you might want to take advantage of. One example, if you have columns which are named created_at/created_on or updated_at/updated_on, rails will automatically update the timestamps for you when records are inserted / updated. Also things like columns named 'id' are understood by ActiveRecord as primary keys and columns named tablename_id are understood as foreign key references.
For working with existing tables, you can override these conventions, telling active record to use alternate columns for these actions. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Using existing database with Ruby on Rails |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|