2012-04-19 44 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

相關問題