自从升级到 Rails 6 后,我开始收到此错误:(ActionDispatch::Http::MimeNegotiation::InvalidType
“ !/! ”不是有效的 MIME 型别)。
在回溯中我有
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_dispatch/http/mime_negotiation.rb:55 → rescue in block in accepts
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_dispatch/http/mime_negotiation.rb:46 → block in accepts
/GEM_ROOT/gems/rack-2.2.3/lib/rack/request.rb:69 → fetch
/GEM_ROOT/gems/rack-2.2.3/lib/rack/request.rb:69 → fetch_header
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_dispatch/http/mime_negotiation.rb:45 → accepts
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_dispatch/http/mime_negotiation.rb:74 → block in formats
/GEM_ROOT/gems/rack-2.2.3/lib/rack/request.rb:69 → fetch
/GEM_ROOT/gems/rack-2.2.3/lib/rack/request.rb:69 → fetch_header
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_dispatch/http/mime_negotiation.rb:70 → formats
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_dispatch/http/mime_negotiation.rb:66 → format
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_controller/metal/instrumentation.rb:26 → process_action
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/action_controller/metal/params_wrapper.rb:249 → process_action
/GEM_ROOT/gems/activerecord-6.1.4.4/lib/active_record/railties/controller_runtime.rb:27 → process_action
/GEM_ROOT/gems/actionpack-6.1.4.4/lib/abstract_controller/base.rb:165 → process
这种 MIME 型别是什么意思?以及如何解决这个错误?
uj5u.com热心网友回复:
defaults: { format: 'js' }
它帮助我添加routes.rb
:
get 'user/card', to: 'user#card', defaults: { format: 'js' }
我在这个动作中只有js
格式供查看。我认为它在类似情况下会有所帮助。
0 评论