I would like to display all the filenames of the files users have uploaded to my Ruby-on-Rails app in a view for admin to see the filename before downloading the file. All the files are stored in a directory.
My UploadController is the following:
class UploadController < ApplicationController
def index
end
def show
end
def uploadFile
uploadedFile = params[:upload][:file]
File.open(Rails.root.join('public','files', uploadedFile.original_filename), 'wb') do |f|
f.write(uploadedFile.read)
end
redirect_to upload_path, :notice => "Thanks for your upload!"
end
def downloadFile
fileName = params[:download][:file].original_filename
send_file Rails.root.join('public','files', fileName)
end
end
show.html.erb (the view I want Admin to be able to see uploaded filenames and download the files) is the following:
<h1>Download a file</h1>
<%= form_for :download, url: upload_admin_downloadFile_path do |f| %>
<%= f.text_field :fileName %><br/>
<br/>
<%= f.submit :DOWNLOAD! %>
<% end %>
This is my upload index.html.erb
<div class="upload_container">
<h1>- UPLOAD A FILE -</h1>
<p> Here you can upload files that you want to share </p>
<%= form_for :upload, url: upload_uploadFile_path do |f| %>
<%= f.file_field :file, :class=> "btn-uploadoldschool" %>
<br/>
<br/>
<br/>
<%= f.submit :UPLOAD!, :class=> "btn-uploadoldschool" %>
<% end %>
<% if user_signed_in? %>
<% if current_user.has_role? :admin %>
<%= link_to upload_admin_url do %>
<% end %>
<% end %>
<% end %>
</div>
All the help is very much appreciated! Thanks, Fox.