How do I map an application/json POST request to the params in rails?

ruby-on-rails

Solution

see the guides for a comprehensive information.

you can simply access to `params[:username]` or even `params['username']` since params is a `HashWithIndifferentAccess`.

Note that you can easily inspect the params using the debugger gem, or just slam a `raise` in your controller action to see them on the error page when in development mode.

Problem

I am being passed in a json body for a post request, but i'm not sure the best way to map this json body to request params in rails: ``` { username: "example-user", password: "password", email: "example@gmail.com", } ``` and in the controller i wish to acccess params["username"], is this possible? how should i do it?

Original source