class ActiveRecord::Base

def self.unprotected_create!(*args)
with_unprotected_attributes { create!(*args) }
end

def self.unprotected_create(*args)
with_unprotected_attributes { create(*args) }
end

def self.unprotected_new(*args)
with_unprotected_attributes { new(*args) }
end

protected

def self.with_unprotected_attributes(&block)
previous_attr_protected = read_inheritable_attribute("attr_protected")
previous_attr_accessible = read_inheritable_attribute("attr_accessible")

write_inheritable_attribute("attr_protected", nil)
write_inheritable_attribute("attr_accessible", nil)

result = yield

write_inheritable_attribute("attr_protected", previous_attr_protected)
write_inheritable_attribute("attr_accessible", previous_attr_accessible)

result
end

end