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