簡體   English   中英

HTML表單不包含在帖子的參數文件數據中

[英]Html form does not include in post's parameters file data

由於我什至無法猜測的原因,我的rails應用程序不再起作用。 我沒有更改rails代碼中的任何內容,因此我想它可能與瀏覽器有關。

簡單形式,由Simple_form生成:

<%= simple_form_for @order, :url => fillparameters_order_path(@order), :remote => true do |f| %>

  <%= f.association :aspectRatio,  collection: @order.project.aspect_ratios %>
  <%= f.input :client_email, :as => :string %>
  <%= f.input :soundtrack, :as => :file %>
  <%= f.input :project_id, :as => :hidden %>
  <%= f.button :submit %>
<% end %>

它生成以下內容:

form id="edit_order_4" class="simple_form edit_order" novalidate="novalidate" method="post" enctype="multipart/form-data" data-remote="true" action="/orders/4/fillparameters" accept-charset="UTF-8"
    <input id="order_soundtrack" class="file optional" type="file" name="order[soundtrack]">
    <input class="btn" type="submit" value="Send!" name="commit">

當然還有其他投入。

但是點擊提交按鈕后,Firebug控制台和webrick日志顯示發送的所有內容都是我的文件字段以外的所有內容:

Started PUT "/orders/4/fillparameters" for 127.0.0.1 at 2013-08-04 21:00:03 +0900
Processing by OrdersController#fillparameters as JS
Parameters: {
    "utf8" => "✓",
    "authenticity_token" => "VpddWLzi7Czzl0L+gbd5wVfjbJ1pQnfI53L86BwbH/E=",
    "order" => {
        "aspect_ratio_id" => "1",
        "client_email" => "****@gmail.com",
        "project_id" => "1"
    },
    "commit" => "Send!",
    "id" => "4"
}

大家有什么想法嗎?

事實是:您不能在rails中使用:remote => true選項上傳文件。 有兩種方法可以使用AJAX進行文件上傳:

  1. Rails方式:使用gem remotepart
  2. jQuery方式:使用Jquery文件上傳插件,有很多這樣的插件,例如https://github.com/blueimp/jQuery-File-Upload

    http://malsup.com/jquery/form/等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM