title: Post JSON to update Rails resource through API
body: <p><strong>The Goal:</strong><br>
  Send a POST request to an API endpoint, and modify that resource using Rails.  I've been at this error for almost 6 hours today with no luck; can someone please point me in the right direction? All relevant details included below:</p>
  
  <p><strong>routes.rb</strong> for the relevant route:<br>
  <code>post '/complete_transportation_request' =&gt; 'api/transportation/complete#complete_request'</code></p>
  
  <p><strong>api/transportation/complete_controller.rb</strong> (the method that handles this request: </p>
  
  <pre><code>def complete_request
   @ride = Transportation.find(params["transportation"]["id"])
   @ride.update(transportation_params)
  end
  </code></pre>
  
  <p>The file from which I'm calling the attempted POST request:  </p>
  
  <pre><code>require 'net/http'
  require 'uri'
  ....  
  def test_post_request(result)
    params = {"transportation"=&gt;{"id"=&gt;6, "state"=&gt;"Complete"}}
    url = URI.parse("http://localhost:3000/complete_transportation_request")
    resp, data = Net::HTTP.post_form(url, params)
  
    puts resp.inspect
    puts data.inspect
    puts resp.body
    puts params
  end
  </code></pre>
  
  <p><strong>error being thrown:</strong>  </p>
  
  <h1>    ActiveRecord::RecordNotFound at /complete_transportation_request</h1>
  
  <blockquote>
    <p>Couldn't find Transportation with 'id'=id</p>
  </blockquote>
  
  <h2>app/controllers/api/transportation/complete_controller.rb, line 10</h2>
  
  <pre><code>``` ruby
  5       @rides = ::Transportation.where(state: "Complete")
  6     end
  7   
  8   
  9     def complete_request
  &gt;  10       @ride = Transportation.find(params["transportation"]["id"])
  11       @ride.update(transportation_params)
  12     end
  13   
  14     private
  15   
  ```
  </code></pre>
  
  <p><strong>Edit 1: <code>params</code> at the point of failure:</strong>  </p>
  
  <pre><code>[2] pry(#&lt;Api::Transportation::CompleteController&gt;)&gt; params
  =&gt; nil
  </code></pre>
  
  <p><strong>Edit 2: Full <code>pry</code> output at point of failure:</strong> </p>
  
  <pre><code>Started POST "/complete_transportation_request" for ::1 at 2015-08-23 19:58:49 -0700
  Processing by Api::Transportation::CompleteController#complete_request as */*
  Parameters: {"transportation"=&gt;"{\"id\"=&gt;\"6\", \"state\"=&gt;\"Complete\"}"}
  "Id = id"
  
  From: .... line 11 Api::Transportation::CompleteController#complete_request:
  
   9: def complete_request
  10:     p "Id = #{params["transportation"]["id"]}"
  11:     binding.pry
  12:     params = JSON.parse(params)
  13:     @ride = Transportation.find(params["transportation"]["id"])
  14:   @ride.update(transportation_params)
  15: end
  
  [1] pry(#&lt;Api::Transportation::CompleteController&gt;)&gt; params
  =&gt; nil
  </code></pre>
  
  <p><strong>Edit 3: What am I missing? Parameters seem to be right there in the log for the request!</strong>  </p>
  
  <pre><code>Started POST "/complete_transportation_request" for ::1 at 2015-08-23 21:37:18 -0700
  Processing by Api::Transportation::CompleteController#complete_request as */*
  Parameters: {"id"=&gt;"7", "state"=&gt;"Complete"}
  
  From: ...../app/controllers/api/transportation/complete_controller.rb @ line 11 Api::Transportation::CompleteController#complete_request:
  
  10: def complete_request
  =&gt; 11:  binding.pry
  12:     params = JSON.parse(params)
  13:     @ride = Transportation.find(params["transportation"]["id"])
  14:   @ride.update(transportation_params)
  15: end
  
  [1] pry(#&lt;Api::Transportation::CompleteController&gt;)&gt; params
  =&gt; nil
  </code></pre>