Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple image uploads in a nested form with carrierwave
    primarykey
    data
    text
    <p>I'm following <a href="http://railscasts.com/episodes/381-jquery-file-upload" rel="nofollow">railscasts episode 381</a> in an attempt to allow multiple image uploads to my app with the carrierwave gem &amp; jQuery File upload. </p> <p>My app is for a college project &amp; is set up with a <strong>hikingtrails model</strong> which has many &amp; accepts nested attributes for a <strong>pics model</strong>.</p> <p>After I set the multiple option of the file_field to true &amp; hard-coding the input name attribute i.e. <code>&lt;%= form.file_field :image, multiple: true, name: "pic[image]" %&gt;</code>, carrierwave stops working, it doesn't upload a single file as it did before.</p> <p>Could this have something to do with using nested forms? I've also tried implementing this <a href="http://lucapette.com/rails/multiple-files-upload-with-carrierwave-and-nested_form/" rel="nofollow">tutorial</a> into my app without any success.</p> <p>I've also tried making both forms multi part rather than just the parent form &amp; removing the simple_form gem that I'm using.</p> <p>I've also tried removing the form partial &amp; putting the nested form in locally but that didn't help. Perhaps it has something to do with how I'm setting the file_field to multiple as this is where the issue began.</p> <p>Any suggestions or an alternative approach would really be appreciated</p> <h1>Models</h1> <pre><code>class Pic &lt; ActiveRecord::Base belongs_to :hikingtrail attr_accessible :img_name, :image, :remote_image_url mount_uploader :image, ImageUploader end </code></pre> <p>&amp;</p> <pre><code>class Hikingtrail &lt; ActiveRecord::Base attr_accessible :description, :duration_hours, :duration_mins, :meta_description, :name, :looped, :pics_attributes validates :name, :presence =&gt; true has_many :pics accepts_nested_attributes_for :pics, :allow_destroy =&gt; :true, :reject_if =&gt; proc { |attrs| attrs.all? { |k, v| v.blank? } } end </code></pre> <h1>Views</h1> <h2>hikingtrails/_form.html.erb</h2> <pre><code>&lt;% @hikingtrail.pics.build %&gt; &lt;%= simple_form_for @hikingtrail, :html =&gt; {:multipart =&gt; true} do |f| %&gt; &lt;%= f.input :name %&gt; &lt;%= f.input :description, :input_html =&gt; { :cols =&gt; 10, :rows =&gt; 3 } %&gt; &lt;%= f.input :looped %&gt; &lt;h2&gt;Images&lt;/h2&gt; &lt;%= render :partial =&gt; 'pics/form', :locals =&gt; {:form =&gt; f} %&gt; &lt;div class="form-actions"&gt; &lt;%= f.submit nil, :class =&gt; 'btn btn-primary' %&gt; &lt;%= link_to t('.cancel', :default =&gt; t("helpers.links.cancel")), hikingtrails_path, :class =&gt; 'btn' %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <h2>pics/_form.html.erb</h2> <pre><code>&lt;%= form.fields_for :pics do |pic_form| %&gt; &lt;div class="field"&gt; &lt;% unless pic_form.object.nil? || pic_form.object.new_record? %&gt; &lt;%= image_tag pic_form.object.image_url(:thumb).to_s %&gt; &lt;% end %&gt; &lt;% if pic_form.object.nil? || pic_form.object.new_record? %&gt; &lt;%= pic_form.file_field :image, multiple: true, name: "pic[image]" %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;% unless pic_form.object.nil? || pic_form.object.new_record? %&gt; &lt;div class="field"&gt; &lt;%= pic_form.label :_destroy, 'Remove:' %&gt; &lt;%= pic_form.check_box :_destroy %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <h1>Terminal Output</h1> <pre><code>Started PUT "/hikingtrails/7" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Processing by HikingtrailsController#update as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"trGCi0Gz+CNRmwAoktcYmeplEKW5bZBtozkduNIXvcI=", "hikingtrail"=&gt;{"name"=&gt;"Dunran Woods", "meta_description"=&gt;"Nice walk through the woods", "description"=&gt;"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "looped"=&gt;"0", "duration_hours"=&gt;"9", "duration_mins"=&gt;"45"}, "pic"=&gt;{"image"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x007f288085cc08 @original_filename="spink_sleepers.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"pic[image]\"; filename=\"spink_sleepers.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#&lt;File:/tmp/RackMultipart20130324-7791-19ma2cb&gt;&gt;}, "commit"=&gt;"Update Hikingtrail", "id"=&gt;"7"} Hikingtrail Load (3.7ms) SELECT "hikingtrails".* FROM "hikingtrails" WHERE "hikingtrails"."id" = $1 LIMIT 1 [["id", "7"]] (0.1ms) BEGIN (0.1ms) COMMIT Redirected to http://0.0.0.0:3000/hikingtrails/7 Completed 302 Found in 6ms (ActiveRecord: 3.8ms) Started GET "/hikingtrails/7" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Processing by HikingtrailsController#show as HTML Parameters: {"id"=&gt;"7"} Hikingtrail Load (3.4ms) SELECT "hikingtrails".* FROM "hikingtrails" WHERE "hikingtrails"."id" = $1 LIMIT 1 [["id", "7"]] Pic Load (0.2ms) SELECT "pics".* FROM "pics" WHERE "pics"."hikingtrail_id" = 7 Rendered collection (0.0ms) Rendered hikingtrails/show.html.erb within layouts/application (2.6ms) Rendered layouts/_navbar.html.erb (0.9ms) Rendered layouts/_footer.html.erb (0.3ms) Completed 200 OK in 41ms (Views: 36.2ms | ActiveRecord: 3.7ms) Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /application.css - 304 Not Modified (0ms) [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/bootstrap_and_overrides.css?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /bootstrap_and_overrides.css - 304 Not Modified (0ms) [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/jquery-fileupload/vendor/jquery.ui.widget.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /jquery-fileupload/vendor/jquery.ui.widget.js - 304 Not Modified (5ms) Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /jquery_ujs.js - 304 Not Modified (0ms) Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /jquery.js - 304 Not Modified (0ms) [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-transition.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /twitter/bootstrap/bootstrap-transition.js - 304 Not Modified (0ms) Started GET "/assets/jquery-fileupload/jquery.fileupload.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /jquery-fileupload/jquery.fileupload.js - 304 Not Modified (0ms) Started GET "/assets/jquery-fileupload/jquery.iframe-transport.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /jquery-fileupload/jquery.iframe-transport.js - 304 Not Modified (0ms) Started GET "/assets/jquery-fileupload/basic.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /jquery-fileupload/basic.js - 304 Not Modified (0ms) [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-modal.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /twitter/bootstrap/bootstrap-modal.js - 304 Not Modified (0ms) [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-alert.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /twitter/bootstrap/bootstrap-alert.js - 304 Not Modified (0ms) [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:17] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-dropdown.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:17 +0000 Served asset /twitter/bootstrap/bootstrap-dropdown.js - 304 Not Modified (8ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-tab.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-tab.js - 304 Not Modified (8ms) Started GET "/assets/twitter/bootstrap/bootstrap-scrollspy.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-scrollspy.js - 304 Not Modified (3ms) Started GET "/assets/twitter/bootstrap/bootstrap-popover.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-popover.js - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-tooltip.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-tooltip.js - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-button.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-button.js - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-carousel.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-carousel.js - 304 Not Modified (0ms) Started GET "/assets/twitter/bootstrap/bootstrap-affix.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-affix.js - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-collapse.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-collapse.js - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/twitter/bootstrap/bootstrap-typeahead.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap/bootstrap-typeahead.js - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/bootstrap.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /bootstrap.js - 304 Not Modified (0ms) Started GET "/assets/twitter/bootstrap.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /twitter/bootstrap.js - 304 Not Modified (0ms) Started GET "/assets/pics.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /pics.js - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/static_pages.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /static_pages.js - 304 Not Modified (0ms) Started GET "/assets/hikingtrails.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /hikingtrails.js - 304 Not Modified (0ms) Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /application.js - 304 Not Modified (2ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true Started GET "/assets/fontawesome-webfont.woff?v=3.0.2" for 127.0.0.1 at 2013-03-24 13:55:18 +0000 Served asset /fontawesome-webfont.woff - 304 Not Modified (0ms) [2013-03-24 13:55:18] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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