我的 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"]
我收到以下错误:
具有#include 方法的对象?或者需要 proc 或 lambda,并且必须作为配置哈希的 :in 选项提供。
为什么会这样?