Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Finally find an answer on my question.</p> <p>The error was in these strings of code:</p> <pre><code>params[:qqfile].each do |p| tempfile = open(p.original_filename) puts tempfile @uploader.store!(tempfile) end </code></pre> <p>I have understood, that I need to pass an object <a href="http://api.rubyonrails.org/classes/ActionDispatch/Http/UploadedFile.html" rel="nofollow">ActionDispatch::Http::UploadedFile</a> in Carrierwave store! method. Thats why the mentioned above code shall be the following:</p> <pre><code>params[:qqfile].each do |p| puts p.original_filename puts p @uploader.store!(p) end </code></pre> <p>==================================================================================</p> <p>Hope someone find this solution for multiple file uploading with Carrierwave and without JQuery useful.</p> <p>1) Create an uploader, using Carrierwave.</p> <pre><code> rails g uploader EmailPatterns </code></pre> <p>2) Create a custom action for your controller (watch <a href="http://railscasts.com/episodes/35-custom-rest-actions" rel="nofollow">Railscast#35</a> and <a href="http://railscasts.com/episodes/38-multibutton-form" rel="nofollow">Railscast#38</a> to make it clear) and put there something like this (load_patterns in my case):</p> <pre><code> def load_patterns @uploader = EmailPatternsUploader.new params[:qqfile].each {|p| @uploader.store!(p)} redirect_to contacts_path flash[:success] = "Uploaded successfully" end </code></pre> <p>To make it work you need to specify custom route(config/routes.rb) for your action:</p> <pre><code> resources :contacts do collection { post :load_patterns} end </code></pre> <p>and to create a form, where you will get params with your uploading files (see p.3)</p> <p>3) Create form, where you need to specify the option multiple:true in order to allow user to select several files to load (param name with [ ] is a necessary requirement, because we are loading several files) :</p> <pre><code> &lt;%= form_tag load_patterns_contacts_path, multipart: true, multiple: true do %&gt; &lt;%= file_field_tag 'qqfile[]', id: "upload_pattern", multiple: true %&gt; &lt;%= submit_tag "Load", id: "save_pattern", :class =&gt; 'btn btn-primary btn-success', multiple: true%&gt; &lt;% end %&gt; </code></pre> <p>Then your custom action will work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload