Try creating a file in the lib folder named "extension.rb" with the following contents
$:.unshift File.expand_path(File.dirname(__FILE__)) module Extension module Rails autoload :CustomValidator, "extension/rails/custom_validator" end end
checkout http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html and https://github.com/macournoyer/thin/blob/c8f4627bf046680abb85665f28ab926e36c931db/lib/thin.rb for how this method is used.
The previous code assumes that you wrote your validator as follows
# lib/extension/rails/custom_validator.rb module Extension module Rails class CustomValidator < ActiveModel::EachValidator
And that you included it in your model as follows
class MyModel validates_with Extension::Rails::CustomValidator end
Another option is to define a validator as follows
# lib/extension/rails/custom_validator.rb class CustomValidator < ActiveModel::EachValidator
and then add its directory to the download path of your application
# config/application.rb config.autoload_paths += %W(
And in your model use to check
following:
class MyModel validates :my_property, :presence => true, :custom => true end
source share