ruby - rails block a record for change for another places in the code -


i have ruby on rails application lot of sidekiq workers. of workers can work while (at least few minutes).

how can block record changes places (ie controllers), avoid data conflict when save record in worker?

you need lock model:

account = account.first  account.with_lock   # block called within transaction,   # account locked.   account.balance -= 100   account.save! end 

you can read more here.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -