title: custom validation methods for forms
body: <p>My problem is that my error messages never print and I don't think validate is happening. I am have never done validations before and am trying to learn how to do this.</p>
  
  <p>Controller:</p>
  
  <pre><code>def create
      @requests = Request.new(request_params)
  
      if @requests.save
        redirect_to root_path
        flash[:success] = "Your request has been submitted for approval"
      else
        render 'new'
      end
  end
  </code></pre>
  
  <p>Request model</p>
  
  <pre><code>class Request &lt; ApplicationRecord
  
  validate :borrow_date_bigger_than_current_date, on: :create
  
  def borrow_date_bigger_than_current_date
      if (:borrow_date.to_s &lt; Date.today.to_s)
          errors.add(:borrow_date, "Checkout date cannot be earlier than the current date") 
      end
  end
  </code></pre>
  
  <p>and a form that goes like this</p>
  
  <pre><code>form_for @requests do |request|
  &lt;% if @requests.errors.any? %&gt;
    &lt;div id="error_explanation"&gt;
      &lt;h2&gt;&lt;%= pluralize(@requests.errors.count, "error") %&gt; prohibited this message from being saved:&lt;/h2&gt;
      &lt;ul&gt;
        &lt;% @requests.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;
            &lt;%= msg %&gt;
          &lt;/li&gt;
        &lt;% end %&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
    &lt;% end %&gt;
   ... form stuff below here ...
  end
  </code></pre>