由于我甚至无法猜测的原因,我的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"
}
任何想法,伙计们?
答案 0 :(得分:1)
事实是:您无法使用:remote =&gt;上传文件rails中的true 选项。允许您使用AJAX进行文件上传有两种方法:
Jquery方式:使用Jquery文件上传插件,有很多这样的插件,比如 https://github.com/blueimp/jQuery-File-Upload