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