Sometimes you need to make sure that an attribute on one of your models can’t change once it’s set. For example: you’ll want to make it difficult to change @article.permanent_url.
An easy way to do this is to overwrite the setter method (the one that ends in an ’=’). An even easier way is to install the Immutable Attributes plugin and just do this in your code:
class BobBarker < Users
attr_immutable :age, :haircolor
end
0 responses so far ↓
There are no comments yet... Kick things off by filling out the form below.
Leave a Comment