1
votes

I think I'm loosing it here ... so I have a params hash, that I want to use in a controller:

Parameters: {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"etcetc", "scan"=> {"1"=>{"scan_id"=>"40", "organisation_id"=>"1", "select_scan"=>"false", "role"=>""}, "2"=>{"scan_id"=>"40", "organisation_id"=>"2", "select_scan"=>"false", "role"=>""}, "3"=>{"scan_id"=>"40", "organisation_id"=>"3", "select_scan"=>"false", "role"=>""}, "number"=>"222", "description"=>"nice!", "expert"=>"for dummies", "decentralisation"=>"0"}, "commit"=>"Update Scan", "id"=>"40"}

Now, if return to my view an instance variable, with value:

@q = params[:id]

that gives me '40', as expected.

@q = params['id']

also give me '40'

BUT, that's the only param value I can access? Every other value gives me nil, or an error like:

 @q = params[:scan][:number] # => undefined method `[]' for nil:NilClass
@q = params['scan']['1'][:role] # => undefined method `[]' for nil:NilClass
    @q = params[:scan].to_a # => []
@q = params[:scan].class # => NilClass

I've read about strong params, and all params are permitted, but still, no values are returned?

1

1 Answers

-1
votes

Just a though but as far i could see, your hash structure is under quotes(" ") and your`re trying to access it with symbols(:) whithout .with_indifferent_access

e.g:

@q = params['scan']['number'] 
@q = params['scan']['1']['role'] 
@q = params['scan'].to_a
@q = params['scan'].class

Give a try.