Heroku 上多部分表单的路由问题
这是一个非常奇怪的问题,不幸的是我无法提供大量信息,因为我什至不知道从哪里开始诊断问题。我希望有人能神奇地听到该做什么,我很乐意在必要时进行澄清。
出于某种原因,每当我使用 Chrome 在 Heroku 上提交带有文件附件的新的多部分表单时,我都会在提交到默认的“索引”操作时被发送——也就是说,如果我提交了,我将被发送到的页面GET 而不是 POST。
我在 Rails 中使用标准 RESTful 路由,因此我的 paths.rb 中有以下内容:
resources :documents do
member do
get :download, :follow
end
end
我的表单非常标准:
<%= form_for @document, :html => { :multipart => true } do |f| %>
<!-- Form code -->
<% end %>
但同样,这被视为 GET 而不是 POST 请求,因此我只是重定向到 /文件。即使我手动指定 :method => 也是如此:post
在表单定义中。
真正非常奇怪的事情是,这种情况只发生在 Heroku 上,并且只发生在 Chrome 上。这些表单在我使用 Chrome 的本地开发版本或使用 Safari 的 Heroku 上运行良好。
代码中的任何地方都没有发生重定向,当我检查 Heroku 日志时,它只向 /documents 报告 GET,而从来没有报告带有后续处理的 POST 可以解释这一点。
任何帮助将不胜感激。我真的不知道从哪里开始尝试解决这个问题。
更新: 我使用的是 Mac 版 Chrome,版本 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="✓" /><input name="authenticity_token" type="hidden" value="q8Qv4q9BXdV4yWzsPx9cgZoFGhJHxj6Nzje/SSnYsYo=" /></div>
....
<input type="file" name="document[file]" />
....
</form>
这些路线似乎没有什么问题,其中包括:
POST /documents(.:format) {:action=>"create", :controller=>"documents"}
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.
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.
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
My forms are pretty standard:
<%= form_for @document, :html => { :multipart => true } do |f| %>
<!-- Form code -->
<% end %>
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.
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.
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.
UPDATE:
I am using Chrome for Mac, version 12.0.742.53 beta.
Here is the form output.
<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="✓" /><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"}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能否确认您的视图中有
<%= csrf_meta_tag %>
<代码>
Could you confirm that you have
<%= csrf_meta_tag %>
in your view