I am using the Angular Resource and I don't understand why Rails duplicated the parameters and put it inside the resource name. I just need to understand why this is happening.
// post data
{"title":"asdsad"}
// rails parameters
Parameters: {"title"=>"asdsad", "presentation"=>{"title"=>"asdsad"}}
Duplicate because welcome to Stackoverflow where you need 50 points to comments so this happen. I really so sorry: AngularJS $resource sending out an extra "registration" hash?
I had the same question but I hadn't understood the problem and needed a different solution.
In my passwords controller (for enabling password reset via email), my parameters looked like this:
{"email"=>"eg@eg.com", "code"=>"123", "password"=>"[FILTERED]", "password"=>{"email"=>"eg@eg.com", "code"=>"123", "password"=>"[FILTERED]"}}
I thought, "why are my params duplicated inside of
password
", not realizing that the outerpassword
was coming from the resource name. (Thanks, 7stud!) But if I addedwrap_parameters false
at the top of my controller to flatten out the params, then I couldn't use the 'require/permit' pattern for strong params:To make this more legible, I used
wrap_parameters
to rename the outer password ref in the params. The code:and the resulting params:
{"email"=>"eg@eg.com", "code"=>"123", "password"=>"[FILTERED]", "reset"=>{"email"=>"eg@eg.com", "code"=>"123", "password"=>"[FILTERED]"}}
I then immediately ran into a related issue where for an in-app password reset, I passed in
newPassword
from my form but it was not in my params. By default, params only include attributes from the model.wrap_parameters
let me fix this as well:In other words, what you are seeing is the default way rails enters things in the params hash.