A Rails model has several ActiveRecord methods
that make interacting with the database very simple.
Models can be created, updated
and destroyed very easily.
However, in some situations, one might want to mark a model as “readonly”.
Meaning that only read operations are allowed — no updates
A situation like this may occur in the middle of a big refactoring.
A model has been retired but we may not be ready to wipe it out.
We might still need to read it.
This can be achieved by adding a readonly? method to the class which returns true?.
Now, when we try to update
or delete the model we get an error.
Both options raise the ActiveRecord::ReadOnlyRecord error.
However when we try to touch the model we get no error.
While a touch call doesn’t do much damage,
the update_columns call does.
Unfortunately, marking a model as readonly
does not prevent us from updating the model in all possible ways.
This corrupts the data with unwarranted updates.