Skip to content

See and learn

March 16, 2011

See difference between new and create

ruby-1.9.2-p0 :001 > Product.count

=> 0

ruby-1.9.2-p0 :002 > p = Product.create(:name => "test", :price => 10)

=> #<Product id: 3, name: "test", ...>

ruby-1.9.2-p0 :003 > Product.count => 1

ruby-1.9.2-p0 :005 > p.new_record?

=> false

ruby-1.9.2-p0 :006 > q = Product.new(:name => "test", :price => 10)

=> #<Product id: nil, name: "test", ...>

ruby-1.9.2-p0 :007 > Product.count

=> 1

ruby-1.9.2-p0 :008 > q.new_record?

=> true
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: