Rails request parameters -
i'm working on rails 4.1 app devise 3.2.4.
i'm stubbing mobile api workflow, , noticed weird.
if submit post users controller (here i'm simplifying urls):
post /api/mobile_sign_in.json body (json): { "email" : "test@example.com", "password" : "foobar" } rails creates parameters hash:
{ "email" => "test@example.com", "password" => "foobar", "user" => { "email" => "test@example.com" } } that is, adds new member user: { email: "string" } parameters.
something similar happens if send empty json object:
post /api/mobile_sign_in.json body (json): {} which causes rails create parameters hash:
{ "user" => {} } if send truly empty body, parameters hash correctly empty.
i'm not using strong parameters function (yet).
update
i can confirm happens in other controllers too.
for example, in locationscontroller < applicationcontroller, rails automatically grouping (and replicating) attributes can mapped record.
{ "authentication_token" => "blablablablabla", "title" => "test title", "body" => "one 2 three", "latitude" => "0.0", "longitude" => "0.0", "timestamp" => "2014-04-16t16:28:20.441+01:00", "user_id" => "1", "journey_id" => "1", "location" => { "title" => "test title", "body" => "one 2 three", "latitude" => "0.0", "longitude" => "0.0", "timestamp" => "2014-04-16t16:28:20.441+01:00" } } in case, "location" => {} hash added automatically.
i'm not yet using strong parameters, , i'm experimenting test tool.
this controller devise-free.
rails automatically json requests allow easy access of model. can turned off adding wrap_parameters false block controller.
mycontroller < applicationcontroller wrap_parameters false end for more info, actioncontroller::paramswrapper
Comments
Post a Comment