问题
I have a rails active record model Application and need to make it read-only.
I know that having a before_validation method with:
if locked
def readonly?
true
end
end
Will allow me to make it readonly.
The only issue is that, when I need to disable readonly mode, I can not change the locked value to false because the model is already read-only.
I know that attr_readonly :name, :email, :price etc. will allow me to make specific attributes readonly, I am looking for the inverse of this to only allow specific attributes.
Is there a way to make this read-only method except specific attributes?
来源:https://stackoverflow.com/questions/53432372/how-to-make-a-rails-model-read-only-except-for-specified-attributes