2ddbd54c304df255bdb709f2cd50ffe8

Try to refactor send file code

def download
    dl_opts = params[:dl].nil? ?   'attachment' : 'inline'
    dl_img  = params[:type].nil? ? "" : "_#{params[:type]}"
    dl_file = FileUpload.find_by_item_id(params[:id])
    unless dl_file.nil?
      dl_file_type   = dl_file.mime_type
      dl_file_ext    = dl_file_type.item.self_title
      dl_file_name   = "#{dl_file.original_name}#{dl_img}.#{dl_file_ext}"
      dl_file_path   = "#{RAILS_ROOT}/public/upload/#{dl_file.id}/"
      dl_file_title  = dl_file.item.self_title
      dl_public_name = dl_file_title == dl_file_name ? dl_file_name :
                                                       "#{dl_file_title}#{dl_img}.#{dl_file_ext}"
      send_file("#{dl_file_path}#{dl_file_name}",
                :disposition => dl_opts,
                :encoding    => 'utf8',
                :type        => dl_file_type.content_type,
                :filename    => URI.encode(dl_public_name))
    end
  end

Refactorings

No refactoring yet !

Your refactoring





Format Copy from initial code

or Cancel