我有什么:
class User < ActiveRecord::Base
attr_accessor :notify
end
User.new(args)
我在做什么:
User.new(args)
User.notify = true
我需要的是:
User.new(args.merge(:notify => true))
答案 0 :(得分:0)
您展示的内容将起作用。如果您使用:notify
,请务必在attr_accessible
的属性列表中加入{{1}}。
答案 1 :(得分:0)
只要您定义了attr_accessor
,包括任何ActiveRecord中的变量都可以进行质量分配。正如“Wizard of Ogz”所提到的,限制对属性的访问会同时影响数据库属性和实例变量。