I’m trying to figure out how to save an active record instance to the database and then lock it so that you can’t write to it anymore (updates or saves), but you can still read from it.
I’d like to be able to do it upon creation in the model itself.
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.
Rather than overwriting the save method, I’d recommend you create a
before_updatehook that always returns false. From the callback documentation:A
before_updatecallback will be run only when attempting to save an already-existing record. When it’s originally created, it will runbefore_createinstead. With the hook, you can be sure it will be called no matter what method is used to save the record. When you overwrite the existingsavemethod, you’ll have to make sure thatsave!,update_attributes, etc. are all overwritten as well.