5

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?

am-rails
  • 1,463
  • 2
  • 16
  • 40

1 Answers1

11

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

TWiStErRob
  • 44,762
  • 26
  • 170
  • 254
Runthral
  • 432
  • 3
  • 6
  • If it still breaks when using "post" (did for me), then use a webserver other than "WebBrick" for development. WebBrick imposes an arbitrary limit on post-request uri-size which can generate this error. – JosephK Mar 30 '17 at 11:59
  • Changing to post if should be a get doesn't seem a good solution even if it works – Imnl Jul 12 '18 at 16:38