send_file Rails3, Ruby 1.9.2

I'm perty new to rails and I have an app where I want to have secure file downloads, so I can't just drop the files in public/data, I need to use send_file. I found the post (pasted at bottom) that explained how to do this. When I go to implement it, I wanted to try the simplest thing first, so I have this code:

datafiles_controller.rb:   def download     send_file('/file_uploads/Productivity.pdf', :disposition => :attachment)   end datafiles/index.html.erb             <%=button_to "Download File", :action=>'download'%>

when I load index.html it gives the error "No route matches {:action=>"download", :controller=>"datafiles"}" so even though "resources :datafiles" is already in my routes.rb file, I added: get "datafiles/download" now the page loads, I click the "Download File" button and it gives me the error "No route matches "/datafiles/download""

I vaguely remember reading that every def in a controller should correspond to it's own erb file, so I created Views/datafiles/ download.erb as a blank page. But that didn't make any difference. I'm at a loss as to what I'm doing wrong, can someone give me some suggestions?

post refered to above:

resources :datafiles will create some default routes, but they don't include download. You need to add a member route for the download action.

http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/

Luke

If I comment out everything in my index action in my datafiles_controller and paste in: send_file('/file_uploads/Productivity.pdf', :disposition => :attachment) it works, so obviously, the send_file command is good, the problem is with my routing. What do I need to add to my routes.rb file so I can create a new download action? or perhaps even more generally does someone know of a good guide that explains routing? I thought having "resources :datafiles" in my routes.rb file was enough and rails would just detect any new actions automatically.

excellent, ty

Are you going to make me do this for you ? :wink:

resources :datafiles do   member do     get :download   end end

And seriously, read this stuff: http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/

Luke

in case someone else has similar problems, the code that I got working is:

downloading: