Wondering if there’s a plugin or best way of setting up an ActiveRecord class so that, for example, when a record enter the “published” state, certain attributes are frozen so that they could not be tampered with.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can freeze an entire AR::B object by setting @readonly to true (in a method), but that will lock out all attributes.
The way I would recommend is by defining attribute setter methods that check for the current state before passing to super:
[EDIT] Or for a large amount of attributes:
Which of course I would advocate pulling into a plugin to share with others, and add a nice DSL for accessing like:
disable_attributes :author, :content, :comments, :when => :published?