method
attr_readonly
v3.2.8 -
Show latest stable
- Class:
ActiveRecord::ReadonlyAttributes::ClassMethods
attr_readonly(*attributes)public
Attributes listed as readonly will be used to create a new record but update operations will ignore these fields.
1Note
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'