title: Handle error messages with Ajax
body: <p>I have a custom validation function that I use for ensuring file size isn’t to large in my model. I upload files using carrierwave</p>
  
  <p>I submit my form via ajax and if there is an error then i render my <code>js.erb</code></p>
  
  <pre><code># Document model
  class Document &lt; ActiveRecord::Base
    mount_uploader :media, MediaUploader
    belongs_to :user
    belongs_to :skill
  
    validates :media, presence: { message: 'At least 1 File is required' }
    validate :media_size_validation, :if =&gt; "media?"
  
    def media_size_validation
      if media.size &gt; 1.megabytes
        errors.add(:document, "Files should be less than 1MB")
      end
    end
  end
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>def create
    @document = current_user.documents.new(document_params)
     respond_to do |format|
       if @document.save
        format.html { redirect_to root_path, notice: success_save_msg }
        format.js
       else
        format.html
        format.js { render action: 'create.js.erb' }
       end
     end
   end
  </code></pre>
  
  <p>So if i upload a document with no file (:media), i get an error displayed, however if i upload a document with a file over 1mb i get </p>
  
  <pre><code>`Missing template documents/create, application/create`
  </code></pre>
  
  <p>Form</p>
  
  <pre><code>&lt;% if @document.errors.any? %&gt;
  &lt;div id="error_explanation" class="alert-dismissable"&gt;
    &lt;button type="button" class="close" data-dismiss="alert"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;span class="sr-only"&gt;Close&lt;/span&gt;&lt;/button&gt;
    &lt;h2&gt;&lt;%= pluralize(@document.errors.count, "error") %&gt; prohibited this record from being saved&lt;/h2&gt;
      &lt;ul class="error_list"&gt;
        &lt;% @document.errors.full_messages.each do |msg| %&gt;
          &lt;li&gt;&lt;%= error_edit(msg) %&gt;&lt;/li&gt;
        &lt;% end %&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
    
  
  <p>Am i missing something here when dealing with the error if validation fails for the carrierwave image? Why would my create action not render my js.erb file?</p>
  
  <p>Thanks</p>