Best Approach to Upload Multiple Files in Ruby on Rails

I asked a similar question here with unsuccessful answers: Sort + Folder / Rails of nested association before_save

So, I reformulate my question:

What is the best approach in Rails to upload multiple files at once and associate them with an object that has not yet been saved? (for example, a model (girl) that is saved in the database when the creation action is completed (the save button is pressed).

Many ideas come to my mind (save the ajax object before it tries to load images, add a token to the images, and then add the model identifier after saving the model object), but I'm pretty sure that many people did this and there was a general way or better approach for this.

Thank you in advance! Martin.

+3
source share
2 answers

I use this with one of my rails 3 applications:

= form_for :import_csv, :url => {:action => :import_csv}, :html => {:multipart => true} do |f|
  = f.file_field :csv
  = f.submit 'Upload CSV'

Creates a temporary file that can be obtained using

CSV.open(params[:import_csv][:csv].tempfile.path)

I see no reason why this could not be expanded to several downloads, and gain access to params[:import_csv][:whatever]

Note ** handling of tempfiles has changed a bit in rails 3.0.3, so it is used in the above code .tempfile.path, which is not required in previous versions.

+3
source

, :
1. SWFUpload "store_image", , ... .
2. JS, . "2312111: 3231231: 323212".
3. "" , .

, 3 . cron .

, .

__

0

Source: https://habr.com/ru/post/1778739/


All Articles