如何只加载ActiveModel验证?

时间:2016-06-03 16:43:20

标签: validation activemodel

我想在一个小的Roda应用程序中使用ActiveModel::Validations,我真的想保持它小,我想避免在其中加载整个ActiveModel。有没有办法只需要ActiveModel::Validations

至少activemodel-4.2.6.尝试require 'active_model/validations'结果

/home/bbozo/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validations/format.rb:4:in `<module:Validations>': uninitialized constant ActiveModel::Validations::EachValidator (NameError)
        from /home/bbozo/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validations/format.rb:3:in `<module:ActiveModel>'
        from /home/bbozo/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validations/format.rb:1:in `<top (required)>'
        from /home/bbozo/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validations.rb:405:in `require'
        from /home/bbozo/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validations.rb:405:in `block in <top (required)>'
        from /home/bbozo/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validations.rb:405:in `each'
        from /home/bbozo/.rvm/gems/ruby-2.2.4/gems/activemodel-4.2.6/lib/active_model/validations.rb:405:in `<top (required)>'

Hmff,好的,写这个问题我找到了解决方案^ _ ^

1 个答案:

答案 0 :(得分:1)

我设法加载&#34;仅#34; ActiveModel验证及其依赖性,我最终要求

require 'active_support/concern'
require 'active_model/validator'
require 'active_model/validations'
require 'active_model/naming'
require 'active_model/callbacks'
require 'active_support/callbacks'
require 'active_model/translation

只是为了传递这个:

class Foo
  include ActiveModel::Validations
end

因此我似乎需要整个活动模型或找到替代验证框架。