Rails: Difference between create and new methods in ActiveRecord? -


i'm following rails 3.0 tutorial lynda.com.

what's difference between these 2 lines?

first_page = page.new(:name => "first page")  first_page = page.create(:name => "first page") 

by way, great tutorial; recommend other newbies me.

basically new method creates object instance , create method additionally tries save database if possible.

check activerecod::base documentation:

create method creates object (or multiple objects) , saves database, if validations pass. resulting object returned whether object saved database or not.

new method new objects can instantiated either empty (pass no construction parameter) or pre-set attributes not yet saved (pass hash key names matching associated table column names).


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -