[Rails] Downloading files not stored in database?
Hello list,
I am trying to add functionality to my application that will allow users
to download files that are not stored in a database.
All the examples I have found find the file by ID. which I can not do.
Here is my code from the view:
<h1>Browse files for download</h1>
<% form_for(:download, :url=>{ :controller=>"download",
:action=>"download"}, :html => {:multipart => true}) do |f| %>
<table>
<tr>
<th>Files</th>
</tr>
<% @files =
Dir.glob("/home/resource_portal/website/public/data/upload/*") %>
<% @files.each do |file| %>
<tr>
<td><%= link_to file, :controller => "download", :action => :download
%></td>
</tr>
<% end %>
</table>
<% end %>
I dont think I need the form_for line at the top, but the fiew is still
rendering ok, so have just left it in for now.
If I could get the text that is shown for each link stored in to a
variable I could parse it to the upload method in the controller (I
think). I would then be able to use this variable in the send_file
method, instead of specifying a path manually.
Any ideas on how to do this or better suggestions would be great.
Cheers,
Jen.
Below is code from my controller so far. I have commented out the
send_file line for now, so I could test the view rendered ok.
class DownloadController < ApplicationController
require 'grit'
include Grit
#First check the user is logged in
before_filter :authenticate
#First get a list of files from git, so the user can decide what to
download.
def index
download = Download.new
render 'download'
end
def download
#Create string for the directory
directory = "/home/resource_portal/website/public/data/upload/"
#send_file(directory + params[:file], :disposition => :attachment)
end
end
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home