0

我正在尝试使用以下方法验证状态字段的输入:

include ActionView::Helpers
class Credentials < ActiveRecord::Base
    attr_accessible :license_number, ...:address_zip_code,

    ...

    validates :license_number,  presence: true, length: { minimum: 4 }
    ...
    validates_inclusion_of :current_practice_address_state, :in => state_list

end

变量 state_list 是 helpers/credentials_helper.rb 中描述的数组

测试我遇到未定义局部变量错误的模型

$ bundle exec rspec spec/models/credentials_spec.rb
in `method_missing': undefined local variable or method `state_list' for #<Class:0x007f86a1844250> (NameError)

助手类看起来像:

 module CredentialsHelper
        state_list = %w(AL AK...WY)
 end
4

1 回答 1

0

您的电话include必须在课堂内:

class Credentials < ActiveRecord::Base
  include ActionView::Helpers
  ...
end
于 2012-11-14T14:48:18.640 回答