Hello,
I am trying to provide a link which, when clicked, will supply a
folder which I've previously selected for users to click and open
various files in (some pdf, some .doc, maybe even .odt).
In routes.rb I put:
get 'public' => 'people#upload'
And in people_controller.rb requesting a specific file works to
open the correct download window:
def upload
send_file("C:\\ -- a specific folder and file --", :disposition =>
'attachment' , :type => 'application/pdf')
end
But since I don't want to preselect a file for them, from this
preselected folder, how to I just show the folder and let the user
double-click which one they want to open in another window?
Thanks,
Barney
1) Get the filenames: Dir.foreach or Dir.glob.
2) Create a view that provides a list of links, one for each file.
3) The links connect to another action, which sends the file.
Why is your action named 'upload'? How about 'download'?
Could you provide a code example of the connection between the links
and an action that sends the file? I now have a list of links on a
page but clicking them gives:
"Firefox doesn't know how to open this address, because the protocol
(c) isn't associated with any program."
Thanks,
Barney
Thanks 7stud! Your code works and I integrated it with my version.
The only changes I made were to redo RAILS_ROOT to use: dir_path =
Rails.root.join("public","resumes")
and to make the send_file more "Windowsy" in this way:
send_file("#{dir_path}\\#{fname}", :filename => fname)
Never use backslashes in paths. ruby and other modern languages can
handle forward slashes for path separators no matter what os the program
is running on.
Thanks 7stud! Your code works and I integrated it with my version.
The only changes I made were to redo RAILS_ROOT to use: dir_path =
Rails.root.join("public","resumes")
As of Rails 3.0.7 RAILS_ROOT and RAILS_ENV are deprecated.
Rails.root and Rails.env are preferred.