Rails update attributes without validations

While working on a functionality, I came across a situation where I was required to update the model which had a lot of validations specified. It is possible to update a single attribute and save the record without going through the normal validation procedure using update_attribute but when you need to do it for multiple attributes, there is no built-in method for that.

So I went ahead and wrote this method for updating multiple attributes without going through the validations.

def update_attributes_without_validations(attributes)
  attributes.keys.each { |k|
    self.send(k + '=', attributes[k])








Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s