I have the following in my ActiveRecord validation:
validates :username, :exclusion => { :in => %w(admin admins administrator administrators), :message => "\"%{value}\" is reserved."}
which works as it should. But when I replace it with:
validates :username, :exclusion => { :in => @reserved_words, :message => "\"%{value}\" is reserved."}
@reserved_words = ["admin","admins","administrator","administrators"]
I get the following error:
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.
Why is this happening?
Do you really initialize your
@reserved_wordsvariable AFTER it’s been used? Your lines should be swapped!