ActiveRecord transaction, I need some way to lock the record/table for reading, so the user was not able to select from this table, while the transaction being executed.
Basically, I need something like this
s = System.first
# Something to lock the table or selected record for reading
Does anyone have an idea on how to do that?
It seems you are looking for Pessimistic Locking. You can use the
lock method like a scope. Additionally, you should use the bang-version
update_attributes! in order to raise an exception when things go wrong.
System.transaction do s = System.lock.first s.update_attributes!(some_params) end