ruby - Rails update_attributes without save? -
is there alternative update_attributes not save record?
so like:
@car = car.new(:make => 'gmc') #other processing @car.update_attributes(:model => 'sierra', :year => "2012", :looks => "super sexy, wanna make love it") #other processing @car.save
btw, know can @car.model = 'sierra'
, want update them on 1 line.
i believe looking assign_attributes
.
it's same update_attributes doesn't save record:
class user < activerecord::base attr_accessible :name attr_accessible :name, :is_admin, :as => :admin end user = user.new user.assign_attributes({ :name => 'josh', :is_admin => true }) # raises activemodel::massassignmentsecurity::error user.assign_attributes({ :name => 'bob'}) user.name # => "bob" user.is_admin? # => false user.new_record? # => true
Comments
Post a Comment