有人可以帮我理解下面的代码。
def self.with_optimistic_lock(attrs)
begin
payment = where(attrs).first_or_create
yield(payment)
payment.save!
rescue ActiveRecord::StaleObjectError, ActiveRecord::StatementInvalid, ActiveRecord::RecordInvalid => e
retry
end
end
attrs
参数的散列在哪里。Post
是继承自的类ActiveRecord::Base
。
这是来自https://github.com/fantgeass/rails-test-tasks/blob/master/app/models/payment.rb的代码片段