Currently, updates to read-only attributes fail silently. For example:
class ReadOnly < ActiveRecord::Base attr_readonly :name end record = ReadOnly.create(name: "original") record.update(name: "changed") # true record.reload.name # "original"
This behavior is highly unexpected to me because it provides no feedback that the updates were not persisted, a significant exception to the normal behavior of #update and #save.
Raising an error whenever an update is attempted, or treating attr_readonly as a validation both seem like good options to me. I’ve attempted to implement the former (mostly because it was simpler) here: https://github.com/CJStadler/rails/commit/3fe8a29429a3dade8877513db653851b7a43333d.
I realize this would be a breaking change and can’t be undertaken lightly, but the current behavior feels like a big “gotcha”, and one that’s difficult to debug.