I have a Rails app in which I am using HAML for markup. In one haml file (bob.html.haml) I have the following
= form_tag bob_scorecard_dashboard_index_path :multipart=>true do
= file_field_tag 'file[]', multiple: true
= submit_tag "Import"
In the associated controller I have
def bob
pp 'Do process logic on this file now... '
file = params[:file]
if (!file.nil?)
pp 'hey buddy'
pp file[0]
#pp file[1] #This would show the second file uploaded, etc.
#pp file[2] #Third file uploaded... and so on
end
I can see that whenever I hit upload (the button labeled 'Import'), my method 'bob' gets called. What I would love is for the files I attached in the file upload utility rendered by HAML to be accessible/to be able to manipulate them in any way. Currently params[:file] contains an array of Strings... those strings are the filenames of what the user uploaded. But the actual files are not saved in any temp location, and, as such, can not be manipulated in any way. It seems to me perhaps the HAML piece is not doing it's job... no file is being uploaded to the server that the application is being run on when I hit Submit, so far as I can tell. Instead, I just get a String of what the filename that they uploaded was... but no actual file.
This is a legacy app for which I cannot use Paperclip or Carrierwave - useful utilities I've used in other projects. If at all possible, I want to upload and manipulate the uploaded files in 'pure' ruby and HAML, alone. Is this possible?
Minor mistake on your part. That form declaration should be this:
= form_tag bob_scorecard_dashboard_index_path, :multipart => true do
↑
What you had evaluated to something like '/dashboard/scorecard/bob?multipart=true`. It was a regular query string param instead of a form option.