Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Nested array is empty in browser and in RSpec #206

Open
developer88 opened this issue Aug 27, 2014 · 2 comments
Open

Nested array is empty in browser and in RSpec #206

developer88 opened this issue Aug 27, 2014 · 2 comments

Comments

@developer88
Copy link

Faced a strange problem or bug. I have a route with strong parameters method:

 def st_params
    params.permit([:id, logs: [], metric_ids: []])
 end

Then i call it with, for example, rspec:

 post some_path(format:json, metric_ids:[ [1,0,1], [5,1,4] ])

And when i call a st_params method there is no metric_ids param and i have received message in logs: Unpermitted parameters: metric_ids, but if i change st_params method like this:

 def st_params
    p = params.permit([:id, logs: [], metric_ids: []])
    p[:metric_ids] = params[:metric_ids]
    # or just p = params.permit!
    p
 end

Now, everything works fine in browser, but in rspec i have received nil value for metric_ids in any case :( I have not found any information about the problem in documentation. Maybe someone here will help me.

@kaspernj
Copy link

Try this fix:

gem 'strong_parameters', git: "https://github.com/kaspernj/strong_parameters.git", branch: "kj/fixed_integers_as_keys"

Also submitted as PR here:
#221

@thomasfedb
Copy link
Contributor

What version of Rails are you using? If you're using Rails 4 of later, you should submit your issues against rails/rails. This is a compatibility gem for Rails versions prior to 4.

Further, sending an array of array of integers is not something that is generally accommodated by Rails, which generally would represent such data using a hash.

I'd suggest this be closed @fxn.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants