似乎 update_attributes 不允许我更改 id (因此它受到保护),但为什么 rails 不会抛出与其他受保护属性相同的错误?
> rails new mass_assignment_test
> cd mass_assignment_test
> rails g model User name:string
> rake db:migrate
> rails console
>> u = User.create(:name => "ben")
>> u.update_attributes(:id => 5)
=> true
>> u.id
=> 1
>> u.update_attributes(:created_at => Time.now)
ActiveModel::MassAssignmentSecurity:Error
这是 rails 生成的模型(app/models/user.rb):
class User < ActiveRecord::Base
attr_accessible :name
end