Skip to content

Rails: Cross Database development

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:

[code lang="php"]
> ruby script\generate migration Contact
[/code]

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:

[code lang="php"]
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
[/code]

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

[code lang="php"]
> rake migrate
[/code]

Now, generate model and controller for Contact

[code lang="php"]
> ruby script\generate scaffold Contact
[/code]

  • Share/Bookmark

Post a Comment

You must be logged in to post a comment.