title: Unable to figure out Rails api json response for nested attributes and file upload
body: <p>Hi everyone. I am using Rails 4, and i am working on api. Below are my code.</p>
  
  <p>**Api::DocumentsController**</p>
  
  <pre><code>class Api::DocumentsController &lt; Api::BaseController
    skip_before_filter :verify_authenticity_token
    respond_to :json, :xml
  
   def create
     @document = Document.new(document_params.merge(user_id: current_user.id))
     @signers = current_user.signers
  
     @signer_ids = params[:signer_ids]
  
    if @document.save
      @document.create_activity action: :create, recipient: current_user, owner: current_user, custom_field: request.remote_ip
  
      if @signer_ids.present?
       @signer_ids.each do |id|
        unless id.blank?
          DocumentSigner.find_or_create_by(document_id: @document.id, signer_id: id)
        end
      end
    end
  
      @response_message = {:message =&gt; "Your document has been saved.", :document =&gt; @document}
  else
      @response_message = {:message =&gt; "Document creation failed. Please try again!"}
  end
  
  respond_to do |format|
    format.json {
      render json: @response_message
    }
  end
  end
  
    private
      def document_params
       params.require(:document).permit(:document_name, :document, :email_body, :user_id, {:signers_attributes =&gt; [:first_name, :last_name, :email, :is_clicked, :document_id, :user_id, :_destroy]})
      end
   end
  </code></pre>
  
  <p>When i save document without api calls, i have following output.</p>
  
  <pre><code>Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"0gVL8K5nfsQfy/AmBqDQpzTF4aHs7uASSof4b11r4ME=", "document"=&gt;{"document"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x00000006f63398 @tempfile=#&lt;Tempfile:/tmp/RackMultipart20150214-11121-1004vyd&gt;, @original_filename="mozilla.pdf", @content_type="application/pdf", @headers="Content-Disposition: form-data; name=\"document[document]\"; filename=\"mozilla.pdf\"\r\nContent-Type: application/pdf\r\n"&gt;, "document_name"=&gt;"my document", "signers_attributes"=&gt;{"0"=&gt;{"user_id"=&gt;"1", "is_clicked"=&gt;"true", "_destroy"=&gt;"false"}, "1423910618865"=&gt;{"user_id"=&gt;"1", "is_clicked"=&gt;"true", "_destroy"=&gt;"false"}}, "email_body"=&gt;"this is the message value"}, "signer_ids"=&gt;["1", "3"], "commit"=&gt;"Open Document", "payment"=&gt;{"is_payment_with_signature"=&gt;"false", "signer_id"=&gt;"", "payment_amount"=&gt;""}}
  </code></pre>
  
  <p>Document model with pdf upload feature. Document will have many signers and accepts nested attributes for signers.</p>
  
  <p>And signers_attributes which is a nested attributes in document which will save user_id, is_clicked, email_body, etc.</p>
  
  <p>Now i am not able to access this create action through curl command for nested attributes. Can anyone please help me in creating curl command for my create action including signers nested attributes and pdf upload.</p>
  
  <pre><code>curl -X POST -F document=/home/rails/Documents/mozilla.pdf -F 'document[:name]=document nameeee &amp;api_key=-pq45wMEMgjtP5v5GUw3'  http://localhost:3000/api/documents.json
  </code></pre>