Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: Nested form with carrierwave
    primarykey
    data
    text
    <p>I'm not sure what should go in the controller of the embedded class. The parameters passed does show all the embedded class attributes including image attributes, but only the non-image parameters get saved in the database. This tells me that the issue is not with the choice of ORM (Mongoid in this case) but related to the way I'm using carrier wave:</p> <pre><code> Parameters: {"article"=&gt;{"name"=&gt;"New article", "comments_attributes"=&gt;{"0"=&gt;{"remote_image_url"=&gt;"", "name"=&gt;"Comment 1", "content"=&gt;"comment content....", "image"=&gt;#&lt;ActionDispatch::Http::UploadedFile:0x10339d880 @headers="Content-Disposition: form-data; name=\"article[comments_attributes][0][image]\"; filename=\"dh.png\"\r\nContent-Type: image/png\r\n", @original_filename="dh.png", @tempfile=#&lt;File:/var/folders/A1/A1SUPUTUFA8BYB5j+RD2L++++TI/-Tmp-/RackMultipart20120228-21178-1vckii1-0&gt;, @content_type="image/png"&gt;}}, "content"=&gt;"article content"}, "commit"=&gt;"Create Article", "authenticity_token"=&gt;"i14YuJs4EVKr5PSEw9IwKXcTbQfOP4mjbR95C75J2mc=", "utf8"=&gt;"\342\234\223"} MONGODB (89ms) freedb['system.namespaces'].find({}) MONGODB (0ms) freedb['articles'].insert([{"name"=&gt;"New article", "comments"=&gt;[{"name"=&gt;"Comment 1", "_id"=&gt;BSON::ObjectId('4f4daf6a58001652ba000012'), "content"=&gt;"comment content...."}], "_id"=&gt;BSON::ObjectId('4f4daf6958001652ba000011'), "content"=&gt;"article content"}]) </code></pre> <p>Parent model:</p> <pre><code>class Article include Mongoid::Document field :name, :type =&gt; String field :content, :type =&gt; String embeds_many :comments accepts_nested_attributes_for :comments end </code></pre> <p>Child model:</p> <pre><code>require 'carrierwave/mongoid' class Comment include Mongoid::Document field :name, :type =&gt; String field :content, :type =&gt; String field :image, :required =&gt; true field :remote_image_url embedded_in :article, :inverse_of =&gt; :comments mount_uploader :image, ImageUploader end </code></pre> <p>Parent controller:</p> <pre><code> def new @article = Article.new @article.comments.build end def create @article = Article.new(params[:article]) end </code></pre> <p>Parent form:</p> <pre><code>&lt;%= form_for(@article, :html =&gt; {:multipart =&gt; true}) do |f| %&gt; &lt;div class = "field"&gt; &lt;%= f.label :name %&gt;&lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/div&gt; &lt;%= f.fields_for :comments do |c| %&gt; &lt;p&gt; &lt;%= c.label :name %&gt; &lt;%= c.text_field :name %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= c.label :image, "Select Screenshot from your Computer"%&gt;&lt;br /&gt; &lt;%= c.file_field :image %&gt; &lt;/p&gt; &lt;p&gt; &lt;%= c.label :remote_image_url, "or URL from the interweb"%&gt;&lt;br /&gt; &lt;%= c.text_field :remote_image_url %&gt; &lt;/p&gt; &lt;% end %&gt; &lt;div class = "actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre>
    singulars
    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.
 

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