Reputation:
I'm trying to add some basic file-download functionality to my Rails application and have the password_hash
and password_salt
fields for my file model. I also have a function in which a download link to the file is generated, however I'm not totally sure (as I'm sort of reasonably new to Ruby and Rails) how I'd go about actually prompting the user for a password and checking this before proceeding with the file download.
Any help would be appreciated.
Upvotes: 1
Views: 1180
Reputation: 1164
You should target you link to a controller and send the file like this:
before_filter :login_required
def download
send_file '/home/railsway/downloads/huge.zip', :type=>"application/zip"
end
this way you can check the password in you before filter using HTTP Basic Auth for example.
more info: http://www.therailsway.com/2009/2/22/file-downloads-done-right
Upvotes: 1