Skip to content

Instantly share code, notes, and snippets.

@briu
Last active August 29, 2016 16:00
Show Gist options
  • Save briu/7bd81738afe6c3506a32f51b8d2290ed to your computer and use it in GitHub Desktop.
Save briu/7bd81738afe6c3506a32f51b8d2290ed to your computer and use it in GitHub Desktop.
interview
class Finance < ActiveRecord::Base
validate :check_amount
def check_amount
errors.add(:check_amount, 'quantity limit over!') if amount > 100
end
end
first = Finance.first
second = Finance.last
# puts second.amount
# => 90
ActiveRecord::Base.transaction do
first.update(amount: 500)
second.update(amount: 80)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment