2

我有一个名为 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'
4

1 回答 1

0

意识到这是rails变形器的问题classify

分类方法不适用于像“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
于 2012-06-08T12:57:10.777 回答