看起来Remotipart并没有被用于提交我的表单,因此当我查看提交到的表单参数时,图片完全被省略了。
remotipart_submitted?
返回false
参数:{"utf8" => "✓", "product" => {"name" => "RemotipartFails", "price" => "10", "description" => "请工作"}, "action" => "create", "controller" => "products"}
以下是更相关的代码
Gems
gem "jquery-rails"
gem "remotipart", "~> 1.2"
Javascript
//= require jquery
//= require jquery_ujs
//= require jquery.remotipart
表单
<%= form_for(:product, url: products_path, remote: true, html: { multipart: true, class: "form-horizontal" }) do |f| %>
<div class="margin-top-10 margin-bottom-10">
<div class="input-left">
<%= f.text_field :name, { placeholder: "Name", class: "form-control" } %>
</div>
<div class="input-right">
<%= f.number_field :price, { placeholder: "Price", class: "form-control" } %>
</div>
<div class="clearfix margin-bottom-10"></div>
<div class="input-full">
<%= f.text_field :description, { placeholder: "Description", class: "form-control" } %>
</div>
<div class="clearfix margin-bottom-10"></div>
<div class="input-full">
<%= f.file_field :image, { class: "form-control" } %>
</div>
<div class="clearfix margin-bottom-10"></div>
<%= f.submit "Add Product", class: "btn btn-green" %>
</div>
<% end %>
我尝试过不加上
multipart: true
,因为我认为 form_for 会自动添加它,但这并没有帮助。目前,我愿意尝试替代方案(希望仍然能够远程提交带有图像的表单)。