I'm assuming you have a form with a file input to pick the xls file you want to process like this:
<input id="my_model_source" type="file" name="my_model[source]">
To process the xls you could use roo gem.
Option 1:
In some controller (where you are processing the file) you can receive the file like this: params[:my_model][:source]
. This file will be an ActionDispatch::Http::UploadedFile
instance. This class has the instance method path
that will give you a temp file to work with.
So, with roo gem, yo can read it like this:
xls = Roo::Spreadsheet.open(params[:my_model][:source].path, extension: :xlsx)
Option 2:
The option one will work if your importing process is not too heavy.
If indeed, is too heavy you can use Active Job to handle the processing in background.
If you choose Active Job, you:
will lose the opportunity to use ActionDispatch::Http::UploadedFile
's path
method. You will need to generate the temp file on your own. To achieve this you could use cp
command to copy the ActionDispatch::Http::UploadedFile
's path
wherever you want. After use it you can deleted with rm
commnad
will lose a real time response. To handle this you could use Job Notifier gem
I have tried to show roughly what paths you can take.