Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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: "[email protected]",
}

and in the controller i wish to acccess params["username"], is this possible? how should i do it?

like image 214
Kamilski81 Avatar asked Jan 26 '13 19:01

Kamilski81


1 Answers

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.

like image 168
m_x Avatar answered Oct 04 '22 02:10

m_x