4

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?

4

1 回答 1

10

这取决于浏览器/网络服务器,但 URL 的平均限制为 2000 个字符。所以是的,如果您达到限制,请将其更改为 POST。

这将需要更改表单标签:

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

根据您当前的路由,它可能还需要更新您的路由:(因为resources默认情况下使用 POST 请求时会路由到create控制器中的方法)

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

于 2013-07-01T02:12:49.883 回答