Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3, mongoid, carrierwave, nested object form
    text
    copied!<p>I'm using carrierwave to upload photos to a World model. I can't seem to get the upload form right:</p> <pre><code>class World include Mongoid::Document embeds_many :photos accepts_nested_attributes_for :photos end class Photo include Mongoid::Document mount_uploader :image, WorldPhotoUploader embedded_in :world end # show.haml = form_for world, :html =&gt; {:multipart =&gt; true} do |f| = f.fields_for world.photos.build do |photo| = photo.file_field :image </code></pre> <p>This gives me this form input:</p> <pre><code>&lt;input id="world_photo_image" name="world[photo][image]" type="file"&gt; </code></pre> <p>Which doesn't work, I get</p> <pre><code>Cannot serialize an object of class ActionDispatch::Http::UploadedFile into BSON. {"utf8"=&gt;"✓", "_method"=&gt;"put", "authenticity_token"=&gt;"e2PzZlSY0NwiCqDWn7ZMNwqnypP+GC23PcMuy+uGyF0=", "world"=&gt;{"photo"=&gt;{"image"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x00000103182ac8 @original_filename="Black Box fish.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"world[photo][image]\"; filename=\"Black Box fish.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#&lt;File:/var/folders/IY/IY7PGAf2F9OD6CIKr1RQo++++TI/-Tmp-/RackMultipart20110917-57084-zwoyfy&gt;&gt;}}, "commit"=&gt;"Upload", "id"=&gt;"pluto"} </code></pre> <p>The input that seems to work is:</p> <pre><code>&lt;input id="world_photo_image" name="world[photos][][image]" type="file"&gt; </code></pre> <p>But i'm not sure how to create the form to get that</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