You can substitute Foo.create
with Foo.new
.
f = Foo.new(:bar => 1, :baz => 2) # no write
f.update_attribute(:shiz, 3) # write 1
You can also set :shiz
as both attr_accessible
and attr_readonly
.
attr_accessible :bar, :baz, :shiz
attr_readonly :shiz
f = Foo.create(bar: 1, baz: 2, shiz: 3) # write 1
If you now try to modify :shiz
it will not change (as it is readonly):
f.update_attribute(:shiz, 15)
f.reload
f.shiz
=> 3