title: Rails 4.0 Custom Validator Not Working
body: <p>I am attempting to validate some dates in a Rails 4 application and it's not working.</p>
  
  <p>I looked at lots of similar code samples, like this <a href="https://stackoverflow.com/questions/5068820/same-custom-validation-for-several-fields-in-rails">Same custom validation for several fields in Rails</a> and this <a href="http://railscasts.com/episodes/211-validations-in-rails-3" rel="nofollow noreferrer">http://railscasts.com/episodes/211-validations-in-rails-3</a>. (And others more complicated). I don't understand why my example doesn't work. Trying to find the problem, I've stripped out the actual validation code, and left a stub, because the validation doesn't seem to run and that would seem the base problem (or at least, the first problem).</p>
  
  <p>Here's the code in the validator (which is in app/validators/custom_date_validator.rb</p>
  
  <pre><code>class CustomDateValidator &lt; ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      puts "Custom validator was called"
      record.errors[attribute] &lt;&lt; "Date Not Valid" unless false
    end
  end
  </code></pre>
  
  <p>Here's the code from the model:</p>
  
  <pre><code>class CaseInformation &lt; ActiveRecord::Base
    include ApplicationHelper
      validates :started, :custom_date =&gt; true
  </code></pre>
  
  <p>The error message is:</p>
  
  <pre><code>argument out of range
  Extracted source (around line #104): 
  respond_to do |format|
  104 if ( @case_information.update_attributes(params[:case_information]) &amp;&amp; @case_information.update_attributes(params[:law_guardians]) )
  format.html { redirect_to @case_information, notice: 'Case information was successfully updated.' }
  format.json { head :no_content }
  </code></pre>
  
  <p>The error is (I think) intentional, I put in a date of "1/123/2012", but the validator isn't catching it. Well, actually I stripped out all the validation code and have (I think) the validator writing to the log, as it doesn't seem the validator is even running, at least, there's nothing in the log that shows it ran. </p>
  
  <p>I know that the validator code is being found because in the model, if I change the validation name even a bit I get an error that the validation can't be found.</p>
  
  <p>Really stupid noob question I am sure, your patience is appreciated.</p>
  
  <p>Thanks.</p>