Question

I have a form with a checkboxes:

-form_tag filter_path(@page.permalink), :method => 'get' do |f|
  -ftype.producers.each do |producer|
    =check_box_tag "producers[]", producer.id, false        
    =label_tag producer.title
    %br
  =submit_tag 'Сортувати', :name => nil

When I send a request, it sends a hash params with an array of producers.Link then looks like that:

'/pages/:page_id/filter?producers[]=4&producers[]=5'

And I want to make it look that:

'/pages/:pages_id/filter?producers=4,5'

Please help

Was it helpful?

Solution

It shouldn't be a problem, since ?producers[]=4&producers[]=5 will be converted by the framework into params[:producers] array with value [4, 5].
Thus, you already have an array and you don't even have to parse anything.

But if your really want to submit two input values in one parameter, you'd have to employ some javascript. By default, if you have in html form two inputs with the same name, two independent values will be submitted (like in sample url you provided).
So, it's not a Rails question, it's html and javascript question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top