0
我在我的ActiveRecord的验证如下:为什么排除时验证不起作用:指向变量?
validates :username, :exclusion => { :in => %w(admin admins administrator administrators), :message => "\"%{value}\" is reserved."}
其作品,因为它应该。但是,当我将其替换为:
validates :username, :exclusion => { :in => @reserved_words, :message => "\"%{value}\" is reserved."}
@reserved_words = ["admin","admins","administrator","administrators"]
我得到以下错误:
An object with the method #include? or a proc or lambda is required, and must be supplied as the :in option of the configuration hash.
这究竟是为什么?
* facepalm *我知道这一点。 – rocketscientist 2012-04-19 20:40:10