I have the following route:
match '/curl_example' => 'people#curl_post_example', via: :post
In my controller:
class PeopleController < ApplicationController
before_action :set_person, only: [:show, :edit, :update, :destroy]
skip_before_action :verify_authenticity_token, :only => [:curl_post_example]
...
def curl_post_example
Person.create(request.body.read)
render plain: "Thanks for sending a POST request with cURL! Payload: #{request.body.read}"
end
...
I am trying to create a person via curl command with the following...
curl -X POST -d "{"first_name"=>"mista", "last_name"=>"wintas"}" http://localhost:3000/curl_example
When I do this I get this error at the console...
Started POST "/curl_example" for ::1 at 2016-11-08 13:24:46 -0500
Processing by PeopleController#curl_post_example as */*
Parameters: {"{first_name"=>">mista, last_name=>wintas}"}
Completed 500 Internal Server Error in 0ms (ActiveRecord: 0.0ms)
ArgumentError (When assigning attributes, you must pass a hash as an argument.):
Looks like a hash to to me? What am I missing?