I am trying to send a Post request from my iOS app, to my rails API. I can make it so that I receive a status code of 201 (succes/created), however, I can not actually send the data through and create the object in rails.
Here is my code in the rails API:
def create
puts params
product = current_user.products.build(product_params)
if product.save
render json: product, status: 201, location: [:api, product]
else
render json: {errors: product.errors}, status: 422
end
end
private
def product_params
params.require(:product).permit(:title)
end
With the above code, I receive a status code of 400. However, when I remove the (products_params) from the create action, then I receive a 201 status code. So it reaches the server and creates a new object in my database, but its title is just nil.
The problem is this: When I print out the params, They come through like so:
{"{\"title\":\"First Title\"}"=>nil, "format"=>:json,
"controller"=>"api/v1/products", "action"=>"create", "user_id"=>"2"}
Whereas, they need to come through like this:
{"title"=>"First Title", "format"=>:json,
"controller"=>"api/v1/products", "action"=>"create", "user_id"=>"2"}
Currently, on the iOS side, I am sending through the params like so:
let params = ["title": "First Title"]
How can I send the params from the iOS side so that they come through to the rails side in the correct format?
Just for a little more info, this is the response I'm getting in my Terminal when I do the post request:
Thanks

paramsto Rails. Rails is clearly receiving the params the wrong way.