title: how to download files with different extension with send_file command
body: <p>I have the following code, I want to download files of different mime types. Ie docx, pdf etc. I have defined my download action, then bellow am trying to get the file extension for which i direct it to the correct mimetype. But this doesnot seem to work</p>
  
  <pre><code>def download
      @uploadedfile = Uploadedfile.find(params[:id])
      send_data(
          @uploadedfile.upload_file.path,
          :filename =&gt; @uploadedfile.name,
         # :type =&gt; 'application/pdf',          
         # :type=&gt;"*/*",
         # :type=&gt; "application/vnd.openxmlformats-officedocument.wordprocessingml.document",     
         #:type=&gt; MIME::Types.type_for(@uploadedfile.name).to_s, 
         #:content_type =&gt; %w(application/vnd.openxmlformats-officedocument.wordprocessingml.document application/pdf),                   
          :type=&gt; file_extension,
          :stream =&gt; true,     
          :x_sendfile=&gt;true,
          :url_based_filename =&gt; true 
      )               
      flash[:notice] = "The file has been downloaded"
    end  
  
    def file_extension
      @uploadedfile = Uploadedfile.find(params[:id])    
     # ext = File.extname("#{@uploadedfile.name}")   
      ext = File.extname(@uploadedfile.name)
      if (ext == ".pdf")           
          content_type = "application/pdf"
       elsif (ext == ".doc") || ( ext == ".rtf") || ( ext == ".docx")
          content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
       elsif (ext == ".txt")
          content_type = "text/Plain"
       elsif (ext == ".rar")
           content_type = "Application/x-rar-compressed"
       elsif (ext == ".jpeg" || ext==".jpg")
           content_type = "image/jpeg"
       else
           content_type = "Application/octet-stream"
       end
       content_type
    end
  </code></pre>
  
  <p>but this seems not to work, where am i going wrong? Please help</p>