Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Does the Ruby on Rails CarrierWave gem work with Ajax?
  2. Parameters: {"item"=>{"remote_image_url"=>""}}
  3.        
  4. <%= form_for(@item, :url => create_item_path, :html => {:id => "create_item_form", :multipart => true}) do |f| %>
  5.     <p>
  6.       <%= f.file_field :image %>
  7.     </p>
  8.     <p>
  9.       <%= f.label :remote_image_url, "or image URL" %><br />
  10.       <%= f.text_field :remote_image_url %>
  11.     </p>
  12.     <%= f.submit "Save", :id => "save_button" %>
  13. <% end %>
  14.        
  15. $("#create_item_form").submit(function() {
  16.     $.ajax({
  17.       type: "POST",
  18.       url: $(this).attr("action"),
  19.       dataType: "script",
  20.       data:  $("#destination_item").sortable('serialize') + "&" + $(this).serialize()
  21.       });
  22.       return false;
  23. });
  24.        
  25. class Item < ActiveRecord::Base
  26.   attr_accessible :description, :image, :remote_image_url
  27.   belongs_to :user
  28.   has_many :item_sub
  29.   mount_uploader :image, ImageUploader
  30. end
  31.        
  32. create_table "item", :force => true do |t|
  33.     t.integer  "user_id"
  34.     t.string   "title"
  35.     t.string   "image"
  36.     t.datetime "created_at"
  37.     t.datetime "updated_at"
  38.   end