Question

I have a form with a multiselect input like this:

select_tag "activity_types[#{category}]", options_from_collection_for_select(ActivityType.all, "id", "name"), multiple: true

Which generates markup similar to this:

<select id="activity_types_category" multiple="multiple" name="activity_types[category][]"><option value="2">Foo</option>
  <option value="3">Bar</option>
  <option value="4">Baz</option>
</select>

Which is exactly what I want. The issue is that when all options are selected and the form is submitted the url ends up looking something like this:

?activity_types%5Bcategory%5D%5B%5D=2&activity_types%5Bcategory%5D%5B%5D=3&activity_types%5Bcategory%5D%5B%5D=4

That works fine. However I have run into some issues with the completed url being too long for a third party service. They are using the url as a param in their own url. And my url caused a 414 Request-URI Too Large error. I am wondering if there is a way to make the query string look like this:

?activity_types%5Bcategory%5D%5B%5D=2,3,4

Which would fix the problem I am having and make the url a little more readable.

Thanks in advance!

Was it helpful?

Solution

The problem is that you are sending the form data in a GET request via the URL. Generally, form data should be sent via POST which doesn't have this limitation.

And you should not attempt to modify the request structure that Rails (via rack) uses to construct the params hash. Doing so will likely cause you a tremendous headache down the line...

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