For some reason using the CarrierWave gem with Ajax doesn't seem to be working for me. Am I doing something wrong? I followed the 253 CarrierWave Railscast well and it works without AJAX but in my application I need to use AJAX. Here is my code:
The params list after selecting a jpeg in the image file field:
Parameters: {"item"=>{"remote_image_url"=>""}}
new.html.erb:
<%= form_for(@item, :url => create_item_path, :html => {:id => "create_item_form", :multipart => true}) do |f| %>
<p>
<%= f.file_field :image %>
</p>
<p>
<%= f.label :remote_image_url, "or image URL" %><br />
<%= f.text_field :remote_image_url %>
</p>
<%= f.submit "Save", :id => "save_button" %>
<% end %>
application.js
$("#create_item_form").submit(function() {
$.ajax({
type: "POST",
url: $(this).attr("action"),
dataType: "script",
data: $("#destination_item").sortable('serialize') + "&" + $(this).serialize()
});
return false;
});
item.rb
class Item < ActiveRecord::Base
attr_accessible :description, :image, :remote_image_url
belongs_to :user
has_many :item_sub
mount_uploader :image, ImageUploader
end
schema.rb
create_table "item", :force => true do |t|
t.integer "user_id"
t.string "title"
t.string "image"
t.datetime "created_at"
t.datetime "updated_at"
end
I have the carrierwave gem in my gemfile and I haven't changed anything in the app/uploaders/image_uploader.rb.
Thanks for all your help!