Reputation: 3258
No idea why I can't access these params which are of class ActionController::Parameters. Here are the params:
{"{\"base_options\":{\"origin\":{\"name\":\"\",\"phone\":\"\",\"street_1\":\"\",\
"street_2\":\"\",\"zip\":\"\",\"city\":\"\",\"state_iso2\":\"\",\"country_iso2\":\
"US\",\"address_type\":\"commercial\"},\"destination\":{\"name\":\"\",\"phone\":\"\",
\"street_1\":\"932 MyStreet Dr\",\"street_2\":\"\",\"zip\":\"12345\",\"city\":\"Mecio\",
\"state_iso2\":\"NX\",\"country_iso2\":\"US\",\"address_type\":\"residential\"},
\"items\":"=><ActionController::Parameters {"{\"sku\":\"\",\"name\":\"\",
\"length\":{\"units\":\"in\",\"value\":0},\"width\":{\"units\":\"in\",\"value\":0},
\"height\":{\"units\":\"in\",\"value\":0},\"weight\":{\"units\":\"oz\",\"value\":10},
\"discounted_price\":{\"currency\":\"USD\",\"amount\":\"0\"},
\"declared_value\":{\"currency\":\"USD\",\"amount\":\"17.5\"},\"quantity\":1,
\"attributes\":"=>[{"}"=>{",\"customer\":{\"customer_groups\":"=>{"\"\""=>{"},\"cart_id\":\"05\"},
\"connection_options\":{\"auth_token\":\"adfasdf\",\"seller_id\":\"asdf\",\"marketplace\":\"5\"}
,\"zone_options\":"=>[{",\"rate_options\":"=>[{"}"=>nil}]}]}}}}]} permitted: false>,
"controller"=>"welcome", "action"=>"amazon_creds"}
I'm trying to get the sku, but all I ever get is nil
with anything I try. I've tried the following:
params[:sku]
params["sku"]
params[:base_options][:sku]
params.as_json[:base_options]
params.as_json[:sku]
params.to_h[:sku]
params.to_unsafe_h.slice(:base_options)
params.to_unsafe_h[:sku]
params[0]
And yes I've read this ActionContoller::Parameters
Yea I'm at a loss here, no idea how to access these params
. Anyone out there put me out of my misery?
Upvotes: 0
Views: 641
Reputation: 627
Rails will automatically populate the params hash with the deserialized request body if the Content-Type
request header is set to application/json
. It appears that the header is missing for this request. We're adding the appropriate header now.
Upvotes: 1