What I have:
class User < ActiveRecord::Base
attr_accessor :notify
end
User.new(args)
What I'm doing:
开发者_运维知识库User.new(args)
User.notify = true
What I need is something like:
User.new(args.merge(:notify => true))
What you have shown will work. Make sure to include :notify
in the list of attributes for attr_accessible
if you are using that.
As long as you have the attr_accessor
defined, including the variable in any ActiveRecord mass assignment will work. As "Wizard of Ogz" mentioned, limiting access to the attributes affects both database attributes and instance variables alike.
精彩评论