Rails 3.1 client_side_validations Gem错误未唯一性约束的未初始化常量错误

时间:2012-06-06 16:11:09

标签: ruby-on-rails-3 client-side-validation

我有一个名为Business的模型,我在电子邮件中对其进行了唯一性验证。 ajax请求被发送到url

http://localhost.com/validators/uniqueness?case_sensitive=true&business%5Bemail%5D=mabid.mah%40gmail.com

但它给了我一个奇怪的错误

uninitialized constant Busines

s遗失了哪里去了?这是堆栈跟踪

activesupport (3.2.3) lib/active_support/inflector/methods.rb:229:in `block in constantize'
activesupport (3.2.3) lib/active_support/inflector/methods.rb:228:in `each'
activesupport (3.2.3) lib/active_support/inflector/methods.rb:228:in `constantize'
activesupport (3.2.3) lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
client_side_validations (3.1.4) lib/client_side_validations/middleware.rb:59:in `is_unique?'
client_side_validations (3.1.4) lib/client_side_validations/middleware.rb:45:in `response'
client_side_validations (3.1.4) lib/client_side_validations/middleware.rb:16:in `call'

1 个答案:

答案 0 :(得分:0)

意识到这是rails inflector classify

的问题

分类方法不适用于像#34; Business"

这样的单数名称

http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-classify

要解决此问题,请将以下内容添加到config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.singular(/ess$/i, 'ess')
end