Search code examples
ruby-on-rails-3validationcallbackupdate-attribute

Rails update_attribute replacement?


Is there a replacement for update_attribute? I know you can still use it in Rails 3 but you get deprecation messages.

The reason why I need to use update_attribute is because I need to skip validations but run callbacks.

The only way that I've found of doing this (and avoid deprecation messages), is by simply extracting the code from update_attribute:

Object.send("#{attribute}=", value)
Object.save(:validate => false)

I'd like to know if there is another (proper) way of doing this.

Thanks.


Solution

  • I would suggest what the answer is no.

    You cannot pass false to update_attributes to skip validation.

    I would recommend you update_column, but this method skip callbacks. And judging by you question it isn't what you need.

    Update:

    I've found interesting table in that presentation. That I guess can prove my opinion.

    update_(attribute|column)s

    Judging by this table there is only one method which satisfies the conditions.