Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 440
am-rails Avatar asked Dec 26 '22 01:12

am-rails


1 Answers

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

like image 132
Runthral Avatar answered Jan 09 '23 09:01

Runthral