I would like to protect my model in production of of being deleted

It would be nice if rails provide this functionality by default ?
I don't know if there is a functionality like this already but for me its 
something fundamental
If there is i couldn't find nothing till now
Of Course there is the soft delete but this is a different concept 
I dont know if my concept its valid or not or whats the gotchas but why 
protected_attributes and not protected_model?





require "active_record"
require 'active_record/errors'
 
module ActiveRecord
 
  class ProtectedModelError < ActiveRecordError #:nodoc:
    def initialize
      super("Cannot delete record because its protected")
    end
  end
 
 
  module ProtectedModel
    extend ActiveSupport::Concern
 
    protected
    def delete(*args)
      raise ProtectedModelError.new
    end
 
    def destroy_all(*args)
      raise ProtectedModelError.new
    end
 
    def destroy(*args)
      raise ProtectedModelError.new
    end
 
    module ClassMethods
      def delete_all(*args)
        raise ProtectedModelError.new
      end
 
    end
  end
end
 
 
 
class Query < ActiveRecord::Base
  include ActiveRecord::ProtectedModel if Rails.env.production?
end





-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to