Amber: params parser error

Created on 21 May 2018  ·  11Comments  ·  Source: amberframework/amber

Description

params did not parse multi query params

?brand[]=adidas&brand[]=dc

Steps to Reproduce

create form
with elements

input name="brand[]" type="checkbox" value="1"
input name="brand[]" type="checkbox" value="2"

Expected behavior: params[:brand] will be array

Actual behavior: params[:brand] did not exist. params["brand[]"] present

Reproduces how often: always

Versions

0.7.2

question

All 11 comments

@eliasjpr @amberframework/contributors Was this solved on last param refactoring? :sweat_smile:

request.query_params

it returns HTTP::Params(@raw_params={"brand[]" => ["2xist", "2xu", "31-phillip-lim"]})

How to get {"brand[]" => ["2xist", "2xu", "31-phillip-lim"]} ?

I found params.raw_params.fetch_all("brand[]")

request.query_params.to_h # => {"brand[]" => ["2xist", "2xu", "31-phillip-lim"]}

BTW, Can you ask this again on StackOverflow ? I think this would be useful for Amber Community :wink:

If so, please use the tags crystal-lang and amber-framework :+1:

@faustinoaq

request.query_params.to_h # => {"brand[]" => "2xist"}

this method did not work correctly

it should return {"brand[]" => ["2xist", "2xu", "31-phillip-lim"]}

but it didn't return

@faustinoaq i can ask it at StackOverflow but does it make sense if it bug?

i can ask it at StackOverflow but does it make sense if it bug?

I don't think this is a bug, but just design decisions, /cc @eliasjpr

@faustnoaq if it’s feature it better to add it to docs.
I spand time to understend how to get hash of arrays of params it is not obviouse that you need use ‘request.raw_params.fetch_all(“brand[]”)’ to get {“brand[]” => [“brand1”, “brand2”, ....]}

@jaysneg Yeah, I think we can add more documentation on Request & Response section :sweat_smile:

screenshot_20180521_065134

We have an Edit on Github button now, so feel free to contribute opening more issues and even PRs :wink:

cool

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olegsobchuk picture olegsobchuk  ·  5Comments

faustinoaq picture faustinoaq  ·  5Comments

sumwatt picture sumwatt  ·  4Comments

Meldanor picture Meldanor  ·  4Comments

nicbet picture nicbet  ·  7Comments