Routing issues with multi-part forms on Heroku

风流意气都作罢 提交于 2019-12-08 01:08:02

问题


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="&#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"}

回答1:


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



来源:https://stackoverflow.com/questions/6000044/routing-issues-with-multi-part-forms-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!