Created
June 1, 2013 11:30
-
-
Save icem/5690075 to your computer and use it in GitHub Desktop.
Forbid model from get saved or destroyed in Ruby on Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Util::ReadonlyModel | |
extend ActiveSupport::Concern | |
included do | |
before_destroy :raise_readonly | |
end | |
def readonly? | |
true | |
end | |
def raise_readonly | |
raise ActiveRecord::ReadOnlyRecord | |
end | |
end | |
#Usage | |
class YourReadonlyModel < ActiveRecord::Base | |
include Util::ReadonlyModel | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment