:-[] :-|| Vivek Khokhar rambles here :-O :-[]

April 6, 2006

Rails: Cross Database development

Filed under: Ruby — Vivek Khokhar @ 2:34 pm

Its a piece of cake developing applications that run on multitude of Database management solutions.
All you need to keep Database schema scripts handy. Here is how you do it using rails scripts:

> ruby script\generate migration Contact

This will create an empty file in db/migrate folder for contact table. You need to fill it now with the fields you want
for eg:

class Contact < ActiveRecord::Migration
def self.up
create_table :contacts do |table|
table.column :first_name, :string
table.column :last_name, :string
table.column :email, :string
table.column :phone, :string
table.column :address, :string
end
end
def self.down
end
end

Ok.. just found what I was looking for. Pretty detailed document for this: http://rubyonrails.org/api/classes/ActiveRecord/Migration.html

Now, apply the migration

> rake migrate

Now, generate model and controller for Contact

>  ruby script\generate scaffold Contact

Powered by WordPress