anon
anon

Reputation:

Ruby on Rails - Prompting user for password

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

Answers (1)

Adrien Rey-Jarthon
Adrien Rey-Jarthon

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

Related Questions