I am using Ruby on Rails 3.2.9 and I would like to extend the framework with a custom validator located in a sub-directory of the lib/
directory. I implemented the following:
# lib/extension/rails/custom_validator.rb
module Extension
module Rails
class CustomValidator < ActiveModel::EachValidator
# ...
end
end
end
After I restart the server I get the Unknown validator: 'CustomValidator'
error. How can I solve the problem?
Note I: In the config/application.rb
file I stated config.autoload_paths += %W(#{config.root}/lib)
.
Note II: If I put the custom_validator.rb
file "directly under" the lib/
directory (that is, without "sub-directoring" the file) and I use the following code then it works.
# lib/custom_validator.rb
class CustomValidator < ActiveModel::EachValidator
# ...
end