Ants Pants wrote:
> isn't it t.add_column :new_names, :stirng
> 
> http://api.rubyonrails.org/classes/ActiveRecord/Migration.html

Thanks for reply, Ants Pants.
It is from a book, Foundation Rails 2 by Eldon Alameda.  Here is the 
quote from the book:

The most recent version of Rails has added yet another shortcut for us 
in this process as well with the addition of a change_table method. We 
can use this method in a block in the same way that we did with the 
create_table method. It supports a number of new convenience methods 
within the block as well, such as add_XXX (which allows you to easily 
add a new column, for example, calling add_string to add a new string 
field), add_timestamps (which adds the magic created_at and updated_at 
datetime fields), remove_column (which allows you to remove a column and 
can accept multiple fields), and rename (which allows you to rename the 
table).
So we could have rewritten our last migration like this:
def self.up
change_table :comments do |t|
t.add_string :name, :email, :website
end
end
def self.down
change_table :comments do |t|
t.remove_column :name, :email, :website
end
end
Very nice and very DRY.

I need to add 10+ columns to database, and I remember the cleaner way 
from the book.  So I gave it a try.  But somehow an error occured.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to