Request-URI Too Large Error - Get rid of GET?

am-rails picture am-rails · Jul 1, 2013 · Viewed 7k times · Source

I have a form on my site where users can submit answer text to be checked by the controller.
It uses a standard GET form:

<%= form_tag('/submit', method: "get", remote: true) do %>

But I recently got the following error on long answer:

Request-URI Too Large
WEBrick::HTTPStatus::RequestURITooLarge

Should I change the form to POST to fix the error? Would this require any other changes?

Answer

Runthral picture Runthral · Jul 1, 2013

It depends on the browser / web server, but the average limit for a URL is 2000 characters. So yes, if you are hitting the limit change it to POST.

This will require changing the form tag:

<%= form_tag('/submit', method: "post", remote: true) do %>

Depending on your current routing, it might also require updating your route: ( since when using resources POST requests by default are routed to the create method in your controller )

match '/submit', to: 'submit#index', via: :post