Some attributes not updated when validation fails?

Wes Gamble wrote:

I have what I think is a simply question.

If I call update_attributes(params[:whatever]) to update my attributes for object :whatever, does the attribute updating stop as soon as any validation rule fails?

Assume 5 attributes, a-e. If a validates_xxx for "c" fails, does update_attributes return right away?

The reason I'm asking is that I have some attributes that I want to update even if validation for other attributes fails.

Do I need to take complete control of my attribute updating in this case?

I see that "update_attribute" (not plural) seems to address this.

Do I need to update my attributes one-by-one using update_attribute on params.each?

No, update_attributes will update all non-protected attributes in
its argument hash before validation is performed. Is this not
what you're seeing?

Wes Gamble wrote:

One thing to note is that I combined update_attributes and save! together into one function that I named update_attributes! (defined in environment.rb) - seen below.

class ActiveRecord::Base
  def update_attributes!(attributes)
    self.attributes = attributes

This could be it, huh? I'm never actually calling update_attributes here. I will test it.

It's the same way core currently does update_attributes, so it
should be fine, and would be a useful core addition.

Are you sure that the attributes you're updating aren't protected
(including id and STI-type), and that there are no lurking
custom attribute setter methods.