Create_table :products do |t|

At the following: 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.

On Sep 21, 10:38 am, Abder-Rahman A. removed_e[email protected] 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)

Learn what a block is here

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs