Rails / javascript:“参数键太多” - 标准化表单数据的好方法是什么?

发布于 2025-01-01 23:58:48 字数 2050 浏览 1 评论 0原文

我正在使用 Rails 3.1.3。我有一个包含很多字段的表单。提交表单时,我收到此错误

ERROR RangeError: exceeded available parameter key space
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/utils.rb:99:in `block in parse_nested_query'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/utils.rb:93:in `each'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/utils.rb:93:in `parse_nested_query'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/request.rb:302:in `parse_query'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/request.rb:190:in `POST'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/methodoverride.rb:15:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/runtime.rb:17:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/lock.rb:15:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/middleware/static.rb:53:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/engine.rb:456:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/content_length.rb:14:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/rack/debugger.rb:21:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/rack/log_tailer.rb:14:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/handler/webrick.rb:59:in `service'
    /home/james/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
    /home/james/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
    /home/james/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

显然提交的 k/v 对太多。解决这个问题的好方法是什么?我想我会用 javascript 拦截表单的提交,然后以某种方式对其进行编码,以便只有一对 k/v,然后将其解码为应用程序服务器上的普通参数哈希。任何有关此方法的指南或更好的方法将不胜感激。

I'm using rails 3.1.3. I have a form with a lot of fields. When the form is submitted, I get this error

ERROR RangeError: exceeded available parameter key space
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/utils.rb:99:in `block in parse_nested_query'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/utils.rb:93:in `each'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/utils.rb:93:in `parse_nested_query'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/request.rb:302:in `parse_query'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/request.rb:190:in `POST'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/methodoverride.rb:15:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/runtime.rb:17:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.1.3/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/lock.rb:15:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.1.3/lib/action_dispatch/middleware/static.rb:53:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/engine.rb:456:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/content_length.rb:14:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/rack/debugger.rb:21:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.1.3/lib/rails/rack/log_tailer.rb:14:in `call'
    /home/james/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.3.6/lib/rack/handler/webrick.rb:59:in `service'
    /home/james/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
    /home/james/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
    /home/james/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

So apparently there are too many k/v pairs being submitted. What's a good way to get around this problem? I'm thinking that I'll intercept submission of the form with javascript, then encode it somehow so that there's only one k/v pair, then decode it to an ordinary params hash on the app server. Any guidelines for this approach, or a better approach would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千里故人稀 2025-01-08 23:58:48

这个问题是由 Rack 几个版本之前引入的。请参阅这些 (12) 报告。
我通过将以下代码添加到初始值设定项文件来解决该问题。

if Rack::Utils.respond_to?("key_space_limit=")
  Rack::Utils.key_space_limit = 262144 
end

This issue was introduced by Rack few releases ago. Refer to these (1, 2) reports.
I addressed the issue by adding the following code to initializer file.

if Rack::Utils.respond_to?("key_space_limit=")
  Rack::Utils.key_space_limit = 262144 
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文