update_attributes not working in self.up migration

Look at the difference in what "update_attributes" (with an "s") does compared to "update_attribute". You want the singular form for what you're doing. The plural version replaces the entire attributes property of the object.

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

I'm pretty sure that's not correct. You can update only a subset of the attributes with this method.

You're correct, Bob. I let my old habits get the better of me and assumed that self.attributes=attributes;save was doing a simple writer. Silly me!

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

Aryk Grosz wrote:

Yeah I was a little worried, because I like passing my updates as hashes,

I tend to use update_attributes A LOT, even on single attribute assignments.

It seems like that only real difference is that update_attributes saves with validation.

update_attributes will also not update protected attributes.

Is their a huge performance decrease with using update_attributes since it calls the attributes= EXCEPT for the fact that it runs validations of course?

It depends on how expensive validation is, and how important it is to have a sanity check on the internal updates you make to form and non-form attributes.

Aryk Grosz wrote:

Not quite sure what you mean by the internal updates to form and non-form attributes.

Updates to attributes, both those normally used in posted client forms and internal-only attributes, unrelated to form postings.

BTW, how can an attribute in the database be protected? And what does that exactly mean?

See: ActiveRecord::Base