gpt4 book ai didi

ruby-on-rails-4 - Rails 4 远程表单发出错误请求(ParamsParse::ParseError)

转载 作者:行者123 更新时间:2023-12-03 23:35:54 26 4
gpt4 key购买 nike

我在使用简单表单的 Rails 4 中使用远程表单时遇到问题。当我在没有 AJAX 的情况下使用它时它工作得很好但是一旦我将 remote 设置为 true rails 就会抛出一个 ActionDispatch::ParamsParser::ParseErrorunexpected token at 'utf8=%E2%9C% 93&...'.

我不知道是什么原因造成的,但这可能真的很愚蠢,因为我似乎是唯一拥有它的人:)

这是我正在使用的表单标签:

<%= simple_form_for @profile, remote: true, defaults: { wrapper_html: {:class => 'form-group'}, input_html: { :class => 'form-control' } } do |f| %>

这是跟踪 rails 返回给我的:

actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:53:in `rescue in parse_formatted_parameters'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:32:in `parse_formatted_parameters'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:23:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__732810880914274126__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
webrick (1.3.1) lib/webrick/httpserver.rb:138:in `service'
webrick (1.3.1) lib/webrick/httpserver.rb:94:in `run'
webrick (1.3.1) lib/webrick/server.rb:191:in `block in start_thread'

非常感谢您的帮助!

最佳答案

它可能不多,但对于每个不小心遇到与我相同问题的人,我终于找到了解决方案:在我的代码库深处的某个地方,有人为 jQuery Ajax 请求设置了全局设置,将内容类型设置为 JSON。由于 Rails 使用 jQuery Ajax 帮助程序但不使用 JSON(而是普通查询字符串)作为远程表单,Rails 解析器当然会检测到格式错误的 JSON 并抛出错误。删除这些全局设置解决了这个问题。

关于ruby-on-rails-4 - Rails 4 远程表单发出错误请求(ParamsParse::ParseError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20054086/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com