ncuesta / dropzonejs-rails

Spice your Rails apps with some Dropzone sugar!
http://rubygems.org/gems/dropzonejs-rails
MIT License
311 stars 56 forks source link

Problem saving image #9

Closed justinvj closed 11 years ago

justinvj commented 11 years ago

Hi

i need a help, i have form which uses dropzone

= form_tag({:action => :create}, :multipart => true, :id => "NewItemDropzone", :class => "dropzone")

in which i use to save an item. each item will have an image. below is the code of items controller create action

  def create    
    @item = @project.items.new(params[:item])
    respond_to do |format|
      if @item.save
        flash[:notice] = 'Image was successfully added.'
        if params[:finish]
          format.html { redirect_to project_items_path(@project) }
          format.json { head :ok }
        else
          format.html {redirect_to new_project_item_path(@project)}
          format.json { head :ok }
        end        
      else
        format.html { render action: "new" }
        format.json { render json: @item.errors, status: :unprocessable_entity }
      end
    end
  end

js code for dropzone element is below

$("#NewItemDropzone").dropzone({ paramName: "item[image]", maxFilesize: 8, addRemoveLinks: true, maxThumbnailFilesize: true, uploadMultiple: true });

but i need to have the item create action executed for each image droped in. but create action receives image as an array.

Processing by ItemsController#create as JSON
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"this is removed", "item"=>{"image"=>[#>, #>]}, "project_id"=>"dsafasdfc"}

i need to have params[:item][:image] receive a single image instead of array. can you please help?

justinvj commented 11 years ago

Processing by ItemsController#create as JSON Parameters: {"utf8"=>"✓", "authenticity_token"=>"", "item"=>{"image"=>[#<ActionDispatch::Http::UploadedFile:0x007f0c393fc770 @original_filename="DSC047.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"item[image][]\"; filename=\"DSC047.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130721-3345-3pffhb>>, #<ActionDispatch::Http::UploadedFile:0x007f0c393fc888 @original_filename="DSC047_thumb.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"item[image][]\"; filename=\"DSC047_thumb.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130721-3345-g0tq9m>>]}, "project_id"=>"dsafasdfc"}

ncuesta commented 11 years ago

Hi @justinvj, thanks for posting this issue but I'm afraid that should be a question for the author of Dropzone. You may ping him at enyo/dropzone's issues

justinvj commented 11 years ago

hi @ncuesta thanks i get this issue fixed

ncuesta commented 11 years ago

Awesome! Really glad to hear that

niiamon commented 10 years ago

@justinvj how did you fix your problem? I have a few ideas for a fix but want to see what others have done and to provide a clean and straight forward solution as possible.