You can use validation to do this pretty well.
class Thing < ActiveRecord::Base validate :locked_cannot_be_modified private def locked_cannot_be_modified errors.add(:base, "Entry is locked") if changes.any? && whatever_logic_makes_it_locked end end
Alternatively, can you implement readonly? on the model:
class Thing < ActiveRecord::Base def readonly? whatever_logic_makes_it_locked || super end end
this approach will throw an exception instead of a validation error. I think it depends on what you are trying to do, which approach is better.
source share