title: Passing Strong Parameters as JSON in Rails 4
body: <p>I want to pass some nested parameters as JSON for my create action in Rails 4.1.0.</p>
  
  <p>My Controller has :</p>
  
  <pre><code>def create
    debugger
    invoice = @user.invoices.new(invoice_params)
  
    if invoice.save
      render head: 201, location: invoice
    else
      render json: invoice.errors, status: 422
    end
  end
  
  def invoice_params
    params.require(:invoice).permit(:document_no, :customer_id, :currency_id,
        :date, :due_date, :notes, :total, :tax_total, :grand_total, :invoice_status_id,
        invoice_lines: [:product_id, :description, :quantitiy, :price])
  end
  </code></pre>
  
  <p>If I check the sent parameters by using debugger :</p>
  
  <pre><code>(byebug) params
  {{"invoice":{"document_no":"A-500001","customer_id":1,"currency_id":1,
  "date":"2014-09-20","due_date":"2014-09-20","notes":"dasdfsdf",
  "total":100,"tax_total":18,"grand_total":118,"invoice_status_id":1,
  "invoice_lines":"=&gt;{"product_id":1,"quantity":1,"price":200}"=&gt;{}}=&gt;nil}}, 
  "format"=&gt;:json, "action"=&gt;"create", "controller"=&gt;"api/v1/invoices"}
  </code></pre>
  
  <p>Just to mention: I cleared the backslashes from the output above just before I posted here.</p>
  
  <p>My integration test code :</p>
  
  <pre><code>require 'test_helper'
  
  class CreatingInvoiceTest &lt; ActionDispatch::IntegrationTest
    setup do
      @user = User.create!(username: 'foo@example.com', password: '123456')
    end
  
    test 'Creating Invoice' do
  
      post('/api/v1/invoices', {
        invoice: {
          document_no: 'A-500001',
          customer_id: 1,
          currency_id: 1,
          date: Time.now,
          due_date: Time.now,
          notes: 'dasdfsdf',
          total: 100,
          tax_total: 18,
          grand_total: 118,
          invoice_status_id: 1,
          invoice_lines: [{product_id: 1, quantity: 1, price: 200}]
        }
      }.to_json,
      {'Authorization'=&gt; token_header(@user.token)})
  
      assert_equal 201, response.status
      assert_equal Mime::JSON, response.content_type
  
    end
  end
  </code></pre>
  
  <p>My model has :</p>
  
  <pre><code>has_many :invoice_lines
  accepts_nested_attributes_for :invoice_lines
  </code></pre>
  
  <p>I am having the error below:</p>
  
  <p><code>CreatingInvoiceTest#test_Creating_Invoice:
  ActionController::ParameterMissing: param is missing or the value is empty: invoice
      app/controllers/api/v1/invoices_controller.rb:29:in `invoice_params'
      app/controllers/api/v1/invoices_controller.rb:9:in `create'
      test/integration/creating_invoice_test.rb:10:in `block in &lt;class:CreatingInvoiceTest&gt;'</code></p>
  
  <p><strong>I cannot see what I am missing here.</strong></p>