2012-04-19 42 views
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.

这究竟是为什么?

回答

5

您是否真的在初始化@reserved_words变量后使用它?你的线路应该交换!

+1

* facepalm *我知道这一点。 – rocketscientist 2012-04-19 20:40:10

相关问题