8

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?

4

1 回答 1

9

有关全面信息,请参阅指南。

您可以简单地访问params[:username]甚至params['username']因为 params 是一个HashWithIndifferentAccess.

请注意,您可以使用调试器 gem 轻松检查参数,或者raise在开发模式下在控制器操作中猛击 a 以在错误页面上查看它们。

于 2013-01-26T19:36:48.023 回答