forcing an mp3 file to be downloaded

Add a Content-Disposition header:

   Content-Disposition: attachment; filename="foo.mp3"

-pete

Add a Content-Disposition header:

   Content-Disposition: attachment; filename="foo.mp3"

-pete

Check out the send_file method, this will do it for you.

You then create a controller to handle the presentation of the file. Below is an example, if its an image render inline, if not, then force a download. I'm using this with the attachment_fu plugin, which gives me methods like image? to show whether or not its an image. But, you could do something else. Basically, you send the full path to the file to the send_file method. You should then send the correct content-type and specify that the disposition is 'attachment'

class ViewFileController < ApplicationController

  # GET /assets/1   def show     @asset = Asset.find(params[:id])     if @asset.image?       inline     else       attachment     end     rescue ActiveRecord::RecordNotFound       render :text => "return a file not found error here"   end

  private   def attachment     send_file(@asset.full_filename,               :filename => @asset.filename,               :type => @asset.content_type,               :disposition => 'attachment',               :streaming => true,               :buffer_size => 4096)   end

  def inline     send_file(@asset.full_filename,               :filename => @asset.filename,               :type => @asset.content_type,               :disposition => 'inline')   end

end