Drazen
Drazen

Reputation: 2826

POST data not showing up in params for custom route

I have a Rails Route like this

resources :agents do
  member do
    post :location_wifi
  end
end

And a method in controllers/agents_controller.rb like this

def location_wifi
    puts params
    puts params.permit!

end

I send a POST request to that route with a JSON payload like

{ "custom": {"model": "a"} }

When i check the params i can't see the POST payload i sent nowhere. The data i am sending here is not being stored in the database but sent to a google API and that result is later stored. For that reason i don't have a model for it.

What is going on here? Why can't i access the POST payload?

Upvotes: 1

Views: 1039

Answers (1)

Drazen
Drazen

Reputation: 2826

The problem was that i was not sending a Content-Type=application/json header and my API routing namespace defines a :defaults => { :format => 'json' }.

Sending the content header fixed it.

Upvotes: 6

Related Questions