Download Movie through link


I am storing movie data into db.
Now I want to access movie from db and create a link to allow download

But when I click on the link It simply open the movie player and does
not play the movie. player give error in movie file.

When I try to save_as link and save the movie file and play It work's

My code like:

=============== Controller
def download
      @movie = Movies.find(params[:file])
      @headers["Content-Type"] = "video/x-ms-wmv; charset=utf-8"
      render :text => @movie.file

=============== View

<%= link_to movie.filename, {:action => 'download', :id =>
movie.filename, :file => }%>

if i understand correctly you can click that link, choose the option
'save as', download it to you hd and watch it. but you if you click
the link and choose 'open', your video player opens but doesn't show
any content. correct?

if so i don't think it's a problem with your rails app, but with your
operating system. because as i understand it, the file gets send
correctly. maybe try another video-player. are you able to open other
videos on the net (maybe upload one to a ftp and open it with your

alright, then let's take a look at your code...
how does it work? do you store your files in a folder inside your
public-directory and filename points to that location? or do you store
your files inside your database? what exactly is Movie.file and

the following line throws me off (don't understand it):
  render :text => @movie.file

what could help is a look at send_file:

or even the improvement x_send_file:

I believe that the usual thing when sending files is to use the
webserver's filestreaming rather than rendering the file as text.

Try something like

send_file @movie.file_path, :disposition => :attachment

The disposition attachment option is actually set by default, but it
will provide the behavior you want of downloading, instead of trying
to open in the browser