简体   繁体   中英

How to correctly write parameter in url when scope is array type?

I created a scope and pointed it to the array type.

has_scope: by_industry,: type =>: array

And now I want to make this scope working.

I tried to pass parameter in url like this:

http://localhost:3000/v1/find_friends?by_industry=[1,2]

Does not work.

How to correctly write parameter in url when scope is array type?

To pass arrays through query parameters you use the key + brackets syntax:

?foo[]=1&foo[]=2

It's klunky and its ugly but thats how its been done since the early days of the web and this old CGI convention is used by Rack. The main advantage vs foo=[1,2] is that it is language agnostic and the params can be parsed out without interpreting the string (which is a security hazard).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM