Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot serialize an object of class ActionDispatch::Http::UploadedFile into BSON
    primarykey
    data
    text
    <p>I'm following <a href="http://socialmemorycomplex.net/2010/06/02/gridfs-with-mongoid-and-carrierwave-on-rails-3/" rel="nofollow">GridFS with Mongoid and CarrierWave</a> to implement a simple has_many polymorphic relationship and when I attempt to create a new user, with an avatar, through nested attribute assignment, I get:</p> <pre class="lang-rb prettyprint-override"><code>Cannot serialize an object of class ActionDispatch::Http::UploadedFile into BSON </code></pre> <p>Has anyone else encountered this? I noticed a few individuals posted replies to the "GridFS with Mongoid and CarrierWave" article but I was unable to find anyone with an answer.</p> <pre class="lang-rb prettyprint-override"><code># app/models/asset.rb class Asset include Mongoid::Document include Mongoid::Timestamps mount_uploader :file, AssetUploader field :name, type: String referenced_in :attachable, polymorphic: true end </code></pre> <pre class="lang-rb prettyprint-override"><code># app/models/user.rb class User include Mongoid::Document include Mongoid::Timestamps references_one :avatar, as: :attachable accepts_nested_attributes :avatar end </code></pre> <pre class="lang-rb prettyprint-override"><code># config/initializers/carrierwave.rb CarrierWave.configure do |config| config.grid_fs_connection = Mongoid.database config.storage = :grid_fs config.grid_fs_access_url = "/images" end </code></pre> <pre class="lang-rb prettyprint-override"><code># app/uploaders/asset_uploader.rb class AssetUploader &lt; CarrierWave::Uploader::Base end </code></pre> <pre class="lang-rb prettyprint-override"><code># app/views/users/new.html.haml = semantic_form_for(@user, html: { multipart: true }) do |f| = f.inputs do = f.semantic_fields_for :avatar do |af| = af.input :file, as: :file = f.buttons do = f.commit_button "Upload" </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.
    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