Save / update and validate

Hi,

It seems that the validate method in ActiveRecord is not call when doing
an myActiveRecordObject.update, right ?

So, I call the save method instead, and the validation happens…

some has an explanation ?

thanks
arnaud

Arnaud G. wrote:

It seems that the validate method in ActiveRecord is not call when doing
an myActiveRecordObject.update, right ?

Maybe this helps:
update(id, attributes)
Finds the record from the passed id, instantly saves it with the passed
attributes (if the validation permits it), and returns it. If the save
fails under validations, the unsaved object is still returned.
The arguments may also be given as arrays in which case the update
method
is called for each pair of id and attributes and an array of objects is
returned.
Example of updating one record:
Person.update(15, {:user_name => ‘Samuel’, :group => ‘expert’})

Dirk

Arnaud,
ActiveRecord’s update method calls update_attributes internally.
Validation will occur with update_attributes. Check the rdocs for
more info.


Zack C.
http://depixelate.com

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