Skip to content

Instantly share code, notes, and snippets.

@icem
Created June 1, 2013 11:30
Show Gist options
  • Save icem/5690075 to your computer and use it in GitHub Desktop.
Save icem/5690075 to your computer and use it in GitHub Desktop.
Forbid model from get saved or destroyed in Ruby on Rails
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