Reputation: 10368
We need to pass a large array of ids (may be a few thousands of them) to a path in rails:
rails_path(ids: large_id_array)
There is error of Request-URI Too Large
popping up in development passing an array of 2700 ids. What's the size limit when passing an array to a rails path? Is there any way getting around the size limitation?
Upvotes: 0
Views: 945
Reputation: 54892
You can pass as many args in the path as you want with POST params (you were trying to pass GET params):
/users?is_admin=true
the params[:is_admin]
is equal to "true"
in this case)In your case, you should pass the ids as POST params. How to send POST params in a request? Just ask link_to
to use POST
method instead of GET
:
link_to 'Click here!', rails_path(ids: large_array_of_ids), method: :post
Another way to create a POST link:
# HAML code
= form_tag rails_path(ids: large_array_of_ids) do
= submit_tag 'Click here!'
# ERB code
<%= form_tag rails_path(ids: large_array_of_ids) do %>
<%= submit_tag 'Click here!' %>
<% end %>
Upvotes: 4