Flowdock
method

attr_readonly

Importance_1
v3.2.3 - Show latest stable - 1 note - Class: ClassMethods
attr_readonly(*attributes) public

Attributes listed as readonly will be used to create a new record but update operations will ignore these fields.

Show source
Register or log in to add new notes.
September 9, 2015
1 thank

Warning: prevents persistence but doesn't prevent setting

For example:

class Widget < ActiveRecord::Base
  attr_readonly :key
end
w = Widget.create! key: 'foo'
w.update! key: 'bar'
w.key #=> 'bar'
w.reload.key #=> 'foo'