title: Rails 4 Unprocessable Entity Error when making ajax post
body: <p>I am trying to build an ajax object and I am getting a funny error... </p>
  
  <p>Here are my nested form fields</p>
  
  <pre><code>&lt;%= f.fields_for :order_item do |ff| %&gt;
      &lt;div class="col-md-4"&gt;
          &lt;%= ff.hidden_field :quote_id, value: @quote.id %&gt;
          &lt;%= ff.collection_select :category_id, Category.order(:name), :id, :name, include_blank: "Select Category", hide_label: true %&gt;
      &lt;/div&gt;
      &lt;div class="col-md-6"&gt;
          &lt;%= ff.grouped_collection_select :product_id, Category.order(:name), :products, :name, :id, :name, include_blank: true, hide_label: true %&gt;
      &lt;/div&gt;
      &lt;div class="col-md-2"&gt;
          &lt;%= ff.submit "Add Item", class:"btn-u btn-u-blue pull-right", id:"add_item" %&gt;
      &lt;/div&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p>Here is my quote.js.coffee where I am making my ajax call</p>
  
  <pre><code>$('form').on 'click', '#add_item', (e) -&gt;
  e.preventDefault()
  product = $('#quote_order_item_product_id :selected').val()
  quote = $('#quote_order_item_quote_id').val()
  console.log(product)
  console.log(quote)
  $.ajax '/order_items',
    type: 'POST'
    dataType: 'json'
    data: { order_item: { product_id: product, quote_id: quote } }
    success:(data) -&gt;
      alert data.id
      return false
    error: (jqXHR, textStatus, errorThrown) -&gt;
      alert textStatus
      return false
  </code></pre>
  
  <p>Here is my controller (params accepts <code>product_id</code> and <code>quote_id</code>)</p>
  
  <pre><code>def create
  @order_item = OrderItem.new(order_item_params)
  respond_to do |format|
    if @order_item.save
      format.json { render :show, status: :created, location: @order_item }
    else
      format.json { render json: @order_item.errors, status: :unprocessable_entity }
    end
   end
  end
  </code></pre>
  
  <p>Here is my order_item model as requested</p>
  
  <pre><code>belongs_to :quote
  belongs_to :product
    # validates :quantity, presence: true, numericality: { only_integer: true, greater_than: 0 }
    before_save :set_quantity
    before_save :set_unit_price
  
    def total_price
      unit_price * quantity
    end
  
    def set_unit_price
      product = Product.find(self.product_id)
      self.unit_price = product.price
    end
  
    def set_quantity
      if quantity.nil?
        self.quantity = 1
      end
    end
  
    private
    def product_present
      if product_id.nil?
        errors.add(:product, "is not valid or is not active.")
      end
    end
  
    def quote_present
      if quote_num.nil?
        errors.add(:quote, "is not a valid quote.")
      end
    end
  
    def finalize
      self[:unit_price] = unit_price
      self[:total_price] = quantity * self[:unit_price]
    end
  end
  </code></pre>
  
  <p>Here is my route</p>
  
  <pre><code>  resources :order_items, only: [:create, :update, :destroy]
  </code></pre>
  
  <p>I've also tried to make the data being posted in this format</p>
  
  <pre><code>data: { product_id: product, quote_id: quote }
  </code></pre>