Module: ActiveRecord::Persistence

Defined in:
lib/update_attribute_with_validations.rb

Instance Method Summary collapse

Instance Method Details

#update_attribute_with_validations(name, value) ⇒ Object

Raises:

  • (ActiveRecordError)


3
4
5
6
7
8
9
# File 'lib/update_attribute_with_validations.rb', line 3

def update_attribute_with_validations(name, value)
  raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name.to_s)
  with_transaction_returning_status do
    send("#{name}=", value)
    save
  end
end