Assuming this is based on βRails 3 in action,β the sample code actually has the same problem. From the magazine:
WARNING: Can't mass-assign protected attributes: admin (0.1ms) SELECT 1 FROM "users" WHERE "users"."email" = ' sfcarroll2@gmail.com ' LIMIT 1 User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'f9zDB57RDXsziBdGpmnW' LIMIT 1
However, the mass_assignment_sanitizer parameter is not set in the config / environment / development.rb file . By default, the new rails 3.2 project will install this. If it is commented out, the code will be executed. The default value is:
config.active_record.mass_assignment_sanitizer = :strict
The sample code then sets the attribute using the private set_admin method. Is this a good coding practice? I'm not sure, but it works.
This is a great book, by the way.
source share