By default, ActiveRecord takes all fields from the corresponding database table and creates public attributes for all of them.
I think that it\'s reasonable not<
Making the setting private does generate ActiveRecord error.
I put access control code in the overwritten method of the public setter by checking the caller:
def my_private_attribute=(val)
if (caller.first.include?('active_record/base.rb') || caller.first.include?('app/models/myclass.rb'))
self[:my_private_attribute] = val
else
raise Exception.new("Cannot set read-only attribute.")
end
end