Forum: Ruby on Rails update_attribute and validations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c17b1c9b894c3fcdccec587f1b6ee31?d=identicon&s=25 Victor Grey (Guest)
on 2006-01-17 17:16
(Received via mailing list)
Just in case it saves someone else the several hours of insanity I just
went through, update_attributes will not save unless the model
validations are satisfied, but update_attribute (the singular form)
will save the attribute to the database even if the model validations
would fail!

This appears to be a feature, not a bug
(http://api.rubyonrails.com/classes/ActiveRecord/Base.html) although it
is not mentioned in Agile Web Dev with Rails (page 221).

Regards,
Victor Grey
6661ef9d747db3af8896cd94959d717d?d=identicon&s=25 Paul Barry (Guest)
on 2006-01-17 17:28
(Received via mailing list)
Wow, that is odd, you would think it would work the same as
update_attributes.  Or it least there would be a
update_attribute(name,value,validate) where validate is a boolean.
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2006-01-17 17:31
(Received via mailing list)
On 1/17/06, Paul Barry <mail@paulbarry.com> wrote:
> Wow, that is odd, you would think it would work the same as
> update_attributes.  Or it least there would be a
> update_attribute(name,value,validate) where validate is a
> boolean.

It was made specifically for updating things such as boolean fields.
If you want to update more fields without validation, you can do this:

@foo.attributes = params[:foo]
@foo.save(false)

--
rick
http://techno-weenie.net
This topic is locked and can not be replied to.