Nando
Nando

Reputation: 747

Formatting [] array like params Rails

here my view code:

- @categories.each do |c|
%li.menu-drop
= check_box_tag "categories[]", c.id
.tipo-infor
    = c.title

when i submit this form, it generate this url:

http://0.0.0.0:3000/buscar-projetos-com?utf8=%E2%9C%93&categories%5B%5D=3&categories%5B%5D=4&commit=Pesquisar

my question is how to better display this url just like:

http://0.0.0.0:3000/buscar-projetos-com?categories=2,3,4,5

Upvotes: 2

Views: 126

Answers (1)

ljs.dev
ljs.dev

Reputation: 4483

Those %E2's and such are the ASCII representation of those URLs and it is much safer to use those when sending data over the internet. Furthermore commas (,) are not legal in URLs, so they should never be used as neither browsers nor standard libraries will like them.

If you are concerned about "ugly" URL strings, you could submit your form using the POST method vs GET, which will hide all params from the user.

Upvotes: 1

Related Questions