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
Post a Comment