file-uploadruby-on-rails-4paperclipjquery-file-uploadjquery-fileupload-rails

Large file getting uploaded multiple times in jquery file upload


controller

def index
    @assets = Asset.all
    respond_to do |format|
      format.html
      format.json { render json: @assets.map{|asset| asset.to_jq_asset } }
    end
  end

model

class Asset < ActiveRecord::Base
  has_attached_file :upload
  do_not_validate_attachment_file_type :upload
  include Rails.application.routes.url_helpers
  def to_jq_asset
    {
      "id" => read_attribute(:id),
      "name" => read_attribute(:upload_file_name),
      "size" => read_attribute(:upload_file_size),
      "content_type" => read_attribute(:upload_content_type),
      "url" => upload.url(:original),
      "delete_url" => asset_path(self),
      "delete_type" => "DELETE" 
    }
  end
end

For this I have used rails 4, ruby 2.1.0 and for file upload used paperclip and jquery-fileupload-rails gem Thanks in advance.


Solution