开发商!我无法理解接下来的情况
例如我有模型
class Pg::City < ActiveRecord::Base
belongs_to :country
#virtual accessors
attr_accessor :population
#attr_accessible :city, :isdisabled, :country_id
end
我可以使用这样的代码:
c = Pg::City.new({:population=>1000})
puts c.population
1000
但是如果我取消注释上面的 attr_accessible 代码会抛出警告
WARNING: Can't mass-assign protected attributes: population
如何将虚拟属性与模型属性一起用于质量分配?谢谢!