K
K
kramidev2015-02-02 18:10:46
Ruby on Rails
kramidev, 2015-02-02 18:10:46

rails. File download link?

Hi all. There is a User model which has_many Doc(pdf, doc, xls).
How to organize a link to download a file?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
caution, 2015-02-02
@kramidev

making a controller action

def download
    begin
      send_file @file.file_path
    rescue
      flash[:error] = 'File not found.'
    end
  end

in routes
under your controller
a link
doesn't have to wrap it in an exception.

P
Pavel Bakin, 2015-02-02
@recomp

something like this:
= link_to @user.doc.filename, @user.doc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question