在Heroku上使用多部分表单路由问题 [英] Routing issues with multi-part forms on Heroku

查看:57
本文介绍了在Heroku上使用多部分表单路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常奇怪的问题,遗憾的是,由于我什至不知道从哪里开始诊断问题,因此我无法提供大量信息.我希望有人神奇地知道该怎么做,很高兴在必要时澄清一下.

This is a very bizarre problem, and unfortunately I can't provide a ton of information since I don't even know where to begin diagnosing the problem. I'm hoping somebody hear magically knows what to do, and I'm happy to clarify as necessary.

由于某种原因,每当我使用Chrome在Heroku上提交带有文件附件的新的多部分表单时,我都会在提交到默认的索引"操作时发送,也就是说,如果我已经提交了GET而不是POST.

For some reason, anytime I submit a new multi-part form with a file attachment on Heroku using Chrome, I am sent upon submitting to the default "index" action--that is, the page I would be sent to if I had submitted a GET instead of a POST.

我在Rails中使用标准的RESTful路由,所以我的route.rb中包含以下内容:

I'm using standard RESTful routes in Rails, so I have the following in my routes.rb:

resources :documents do
  member do
    get :download, :follow
  end
end

我的表格很标准:

<%= form_for @document, :html => { :multipart => true } do |f| %>
  <!-- Form code -->
<% end %>

但是,再次将其视为GET而不是POST请求,因此我仅被重定向到/documents.即使我在表单定义中手动指定:method => :post,也是如此.

But again, this is being treated as a GET rather than a POST request, so I am simply redirected to /documents. This is true even if I manually specify :method => :post in the form definition.

真正,非常奇怪的是,这仅在Heroku上发生,并且仅在Chrome上发生.表单在使用Chrome的本地开发版本或在Safari的Heroku上均可正常运行.

The really, really bizarre thing is that this is only happening on Heroku and only happening with Chrome. The forms work fine on my local dev version using Chrome or on Heroku using Safari.

代码中的任何地方都没有发生重定向,当我检查Heroku日志时,它只是向/documents报告GET,而从未进行过POST的后续处理可以解释这一点.

There is no redirect occurring anywhere in the code, and when I check the Heroku logs it's only reporting a GET to /documents, never a POST with subsequent processing that could explain this.

任何帮助将不胜感激.我真的不知道从哪里开始尝试解决这个问题.

Any help would be greatly appreciated. I really don't know where to begin trying to solve this.

更新: 我正在使用Chrome for Mac(版本12.0.742.53 Beta).

UPDATE: I am using Chrome for Mac, version 12.0.742.53 beta.

这是表单输出.

<form accept-charset="UTF-8" action="/documents" class="new_document" enctype="multipart/form-data" id="new_document" method="post">
  <div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="q8Qv4q9BXdV4yWzsPx9cgZoFGhJHxj6Nzje/SSnYsYo=" /></div>
  ....
  <input type="file" name="document[file]" />
  ....
</form>

似乎没有什么不对的,其中包括:

Nothing seems amiss with the routes, which include the following:

POST   /documents(.:format)   {:action=>"create", :controller=>"documents"}

推荐答案

您是否可以确认视图中有<%= csrf_meta_tag %>

Could you confirm that you have <%= csrf_meta_tag %> in your view

这篇关于在Heroku上使用多部分表单路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆