Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As I said above, I had a similar problem with Mongoid, <strong>Carrierwave</strong> and GridFS.<br> My solution is super hacky but it worked for me.<br> I had an Image class which is where my image was mounted </p> <pre><code>class Image include Mongoid::Document include Mongoid::Timestamps field :title field :image field :order mount_uploader :image, ImageUploader embedded_in :article end class Article include Mongoid::Document ... embeds_one :image ... end </code></pre> <p>My carrierwave uploader wanted the attributes sent to it with the key of the mount uploader (image). </p> <pre><code>Image.create( :image =&gt; image_attributes) </code></pre> <p>But the article's new/edit form created something that looked like:</p> <pre><code>:article =&gt; { :image =&gt; #ActionDispatch... } </code></pre> <p>instead of</p> <pre><code>:article =&gt; { :image =&gt; { :image =&gt; #ActionDispatch... } } </code></pre> <p>so my solution was to change the name of the field in the form to</p> <pre><code>file_field :article, :photo </code></pre> <p>and then add a photo setter to the article class that created an image</p> <pre><code>model Article include Mongoid::Document ... def photo=(attrs) create_image(:image =&gt; attrs) end end </code></pre> <p>I tried this with image= but it infinitely recursed and did evil things.<br> I also tried this</p> <pre><code>file_field "article[image]", :image </code></pre> <p>without the setter and it didn't raise an exception but it also didn't save my image.</p> <p>as far as i know, paperclip is pretty similar in these regards. Maybe this will work for someone or someone can clean up my mess </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