I'm not sure if this does the same but you could add `readonly` in the
`default_scope`, this way all initialized objects will always be read
only and protected from destruction.
On 04/27/2015 03:05 AM, Ryan Bigg wrote:
In what instance would people be calling destroy on your model without
realising that it's supposed to be protected? Who is this protecting
the model from?
On 27 Apr 2015, at 07:08, Yannis Kolovos <yannis.kolo...@gmail.com
<mailto:yannis.kolo...@gmail.com>> wrote:
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'
moduleActiveRecord
classProtectedModelError<ActiveRecordError#:nodoc:
definitialize
super("Cannot delete record because its protected")
end
end
moduleProtectedModel
extend ActiveSupport::Concern
protected
defdelete(*args)
raiseProtectedModelError.new
end
defdestroy_all(*args)
raiseProtectedModelError.new
end
defdestroy(*args)
raiseProtectedModelError.new
end
moduleClassMethods
defdelete_all(*args)
raiseProtectedModelError.new
end
end
end
end
classQuery<ActiveRecord::Base
include ActiveRecord::ProtectedModelifRails.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
<mailto:rubyonrails-core+unsubscr...@googlegroups.com>.
To post to this group, send email to
rubyonrails-core@googlegroups.com
<mailto: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.
--
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
<mailto:rubyonrails-core+unsubscr...@googlegroups.com>.
To post to this group, send email to rubyonrails-core@googlegroups.com
<mailto: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.
--
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.