Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 31st, 2007, 07:22 AM
Marbin Marbin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 17 Marbin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 20 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old December 31st, 2007, 12:39 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 51 m 47 sec
Reputation Power: 797
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

Reply With Quote
  #3  
Old January 2nd, 2008, 01:12 PM
Marbin Marbin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 17 Marbin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 15 m 20 sec
Reputation Power: 0
Quote:
Originally Posted by Scorpions4ever
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.


Awesome thanks !!!

Reply With Quote
  #4  
Old January 2nd, 2008, 03:42 PM
twostepted's Avatar
twostepted twostepted is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: Central Washington (USA)
Posts: 515 twostepted User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 h 50 m
Reputation Power: 5
Send a message via Yahoo to twostepted
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Using existing database with Ruby on Rails


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway