Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ActiveModel HelperMethods aren't getting mixed in when following the README pattern #446

Open
ccmcbeck opened this Issue · 0 comments

1 participant

@ccmcbeck

The custom validations are really great.

However, when I followed the README pattern of placing each validation in app/validators

class PersonOrCompanyValidator < ActiveModel::EachValidator
  def validate_each(record, attr_name, value)
    if record.first_name.empty? && record.last_name.empty? && record.company.empty?
      record.errors.add(:first_name, :person_or_company)
    end
  end
end

The class definitions work fine but the extensions to ActiveModel::Validations::HelperMethods

module ActiveModel::Validations::HelperMethods
  def validates_person_or_company(*attr_names)
    validates_with PersonOrCompanyValidator, _merge_attributes(attr_names)
  end
end

only get mixed in if I put the module code directly in the model. Am I doing something wrong?

My configuration

gem 'rails', '3.2.6'
gem 'simple_form', '2.0.4'
gem 'client_side_validations', '3.2.1'
gem 'client_side_validations-simple_form', '2.0.1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.