# Create\_table :products do |t|

**URL:** <https://www.ruby-forum.com/t/create-table-products-do-t/195314>\
**Category:** Rails\
**Created:** [September 21, 2010, 4:38pm UTC](https://www.ruby-forum.com/t/create-table-products-do-t/195314 "2010-09-21T16:38:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 21, 2010, 4:38pm UTC](https://www.ruby-forum.com/t/create-table-products-do-t/195314/1 "2010-09-21T16:38:55Z")

</div>

At the following: [Active Record Migrations — Ruby on Rails Guides](http://guides.rubyonrails.org/migrations.html)

You can find:

def self.up  
create\_table :products do |t|  
t.string :name  
t.text :description  
t.timestamps  
end

Regarding this line:

create\_table :products do |t|

What is passed to the block variable “t”, is it :products?

In this case, how can we read:

t.string :name

?

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 21, 2010, 4:55pm UTC](https://www.ruby-forum.com/t/create-table-products-do-t/195314/2 "2010-09-21T16:55:07Z")

</div>

On Sep 21, 10:38 am, Abder-Rahman A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Regarding this line:
> 
> create\_table :products do |t|
> 
> What is passed to the block variable “t”, is it :products?

The create\_table function returns a new instance of the  
TableDefinition class. The |t| assigns it to the t variable.

> In this case, how can we read:
> 
> t.string :name
> 
> ?
> 
> Thanks.

This is calling the string() method on the instance of  
TableDefinition.

Basically it would be the same as doing this:

t = TableDefinition.new()  
t.string(:name)

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 21, 2010, 6:22pm UTC](https://www.ruby-forum.com/t/create-table-products-do-t/195314/3 "2010-09-21T18:22:21Z")

</div>

Learn what a block is here

[http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/](http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/)
