Update_attributes on partially selected model?

I have a claim model representing a medical claim. It has some 130 fields. In one screen, the only option is to update 3 of those fields, status, discount_amount, payout_amount. It seems that if I:

@claim=Claim.find(params[:id], :select => 'id,status,discount_amount,payout_amount')

that it will begin to complain field by field of missing values that I did not select.

Do I have to select * in order to update only three attributes? I could write a method that updates those three via SQL, but what then when I move to a general update screen that updates around 40 of those attributes?



you basically have 2 choices

@claim = Claim.find(params[:id]) # load record
@claim.update_attributes(params[:attributes]) #update specific
attributes and save record


@claim = Claim.update(params[:id], params[:attributes])

both of which basically do the same thing.

ActiveRecord works at the row level, meaning, even if you just want to
change a few fields, the whole record still gets saved, not just the
fields you changed.

if you need your AR objects to be aware of changes possibly made by
others, look into the following plugins:


also, there is another plugin, acts_as_changed, which appears to only
update those attributes that have changed, and not the entire record.