# Make model readonlymoduleModelReadonlyextendActiveSupport::Concernincludeddobefore_destroy:can_not_destroyenddefreadonly?trueenddefcan_not_destroyraiseActiveRecord::ReadOnlyRecord,'data is readonly.'endend
moduleModelReadonlyextendActiveSupport::Concernincludeddoenable_readonlybefore_destroy:can_not_destroyenddefreadonly?self.class.model_readonly?enddefcan_not_destroyifself.class.model_readonly?raiseActiveRecord::ReadOnlyRecord,'data is readonly.'endendmoduleClassMethodsdefenable_readonly@readonly=trueenddefdisable_readonly@readonly=falseenddefmodel_readonly?@readonlyenddefwithout_readonlyold_value=@readonly@readonly=falsebeginyieldensure@readonly=old_valueendendendend
classMyModel<ActiveRecord::BaseincludeModelReadonlyendMyModel.without_readonlydo# do something writing my_models table end