Make attributes mass-assignable only at creation time

Is it possible to have an attribute that can only be assigned when creating a model object?

For example, the username attribute should be mass assigned when the object is created, but not after it (it should be read-only).

+4
source share
1 answer

This is what attr_readonly does:

 class User < ActiveRecord::Base attr_readonly :username end u = User.create(:username => 'dude') u.username # => 'dude' u.update_attributes(:username => 'dudette') u.reload.username # => 'dude' 
+6
source

All Articles