It looks like Remotipart isn't actually being used to submit my form, so the image is completely left out when I look at the params where the form gets submitted to.
remotipart_submitted?
returns false
params: {"utf8"=>"✓", "product"=>{"name"=>"RemotipartFails", "price"=>"10", "description"=>"Please work"}, "action"=>"create", "controller"=>"products"}
Below is more relevant code
Gems
gem "jquery-rails"
gem "remotipart", "~> 1.2"
Javascript
//= require jquery
//= require jquery_ujs
//= require jquery.remotipart
Form
<%= 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 %>
I've tried it without the multipart: true
because I think form_for adds it automatically, but that didn't help.
At this point I'm open to alternative solutions (hopefully allowing me to submit the form remotely with an image still)
data: {type: :json}
to yourform_for
tag? I'm using carrierwave and remotipart to ajax create/update records with images and adding that was the magic that got it working for me. – Hotblooded