[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rails Recipes

kublaikhan55

4/22/2006 9:39:00 PM

Rails Recipes ... has got some very appetizing recipes. However, I have
a hard time starting. For example, the very first recipe,
InPlaceEditing, how and where do I run this code to create the table?

Thanks!

class AddContactsTable < ActiveRecord::Migration
def self.up
create_table :contacts do |t|
t.column :name, :string
t.column :email, :string
t.column :phone, :string
t.column :address_line1, :string
t.column :address_line2, :string
t.column :city, :string
t.column :state, :string
t.column :country, :string
t.column :postal_code, :string
end
end

def self.down
drop_table :contacts
end
end

3 Answers

amrangaye

4/23/2006 3:58:00 PM

0

Hi kublaikha.

Rails questions usually get re-directed to the rails mailing list.
However, as I'm reading this book myself, and I faced exactly the same
problem...

This is a feature of rails called migrations. You can find a good
tutorial at:
http://glu.ttono.us/articles/2005/10/27/the-joy-of-...

Once that has whetted your appetite, you can check out the
ActiveRecord::Migrations docs at
http://rubyonrails.org/api/classes/ActiveRecord/Migr....

Cheers.

Marcin Jurczuk

4/23/2006 7:39:00 PM

0

kublaikhan55@hotmail.com napisaÅ?(a):

> Thanks!
>
> class AddContactsTable < ActiveRecord::Migration
> def self.up
> create_table :contacts do |t|
> t.column :name, :string
> t.column :email, :string
> t.column :phone, :string
> t.column :address_line1, :string
> t.column :address_line2, :string
> t.column :city, :string
> t.column :state, :string
> t.column :country, :string
> t.column :postal_code, :string
> end
> end
>
> def self.down
> drop_table :contacts
> end
> end
>

script/generate migration add_contracts_table
....
...
there will be file created db/migrations/<No>_add_contracts_table
Put it into this file and run:
$ rake migrate

kublaikhan55

4/24/2006 4:15:00 AM

0

Thanks! Just the tutorials I've been looking for.

all the best.