Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6565995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:09:51+00:00 2026-05-25T14:09:51+00:00

I am having problem uploading image to mongodb using rails and carrierwave. This is

  • 0

I am having problem uploading image to mongodb using rails and carrierwave. This is the error message i am getting

Cannot serialize an object of class ActionDispatch::Http::UploadedFile into BSON.

My model looks like this

class Offer
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name, :type => String
  field :desc, :type => String
  field :expiry, :type => Date

   has_one :image, as: :viewable
  embeds_many :locations, as: :locatable
end

and

class Image
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name, :type => String
  field :extension, :type => String
  mount_uploader :image, ImageUploader

  belongs_to :viewable, polymorphic: true
end

And the view is

<%= nested_form_for @offer, :html => {:method => :post, :id => "offerNew", :class => "uniForm", :multipart => true} do |f| %>

<fieldset class="inlineLabels" id="setBiz">
  <div class="ctrlHolder">
    <%= f.label :name, mark_mandatory("Offer Name") %>
    <%= f.text_field :name, :class => "textInput large" %>
    <p class="formHint">Name of the offer to be displayed in ads ex:5% offer on Panasonic vierra LCD </p>
  </div>

   <div class="ctrlHolder">
    <%= f.label :image, "Image" %>
    <%= f.file_field :image %>
    <p class="formHint">Upload image </p>
  </div>

</fieldset>
<% end %>

these are the parameters sent to controller

"utf8"=>"✓",
 "authenticity_token"=>"8GhVGBg2zTI9FQwZmnKiZtBmgM5DiaQmPZaUIhNeF6I=",
 "offer"=>{"catid"=>"4e590231b356f8015f000030",
 "name"=>"aaaaaaaaaaaaaaaaaaaa",
 "expiry"=>"22/09/2011",
 "image"=>#<ActionDispatch::Http::UploadedFile:0xb412e30 @original_filename="51MF4101AA000.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"offer[image]\"; filename=\"51MF4101AA000.jpg\"\r\nContent-Type: image/jpeg\r\n",
 @tempfile=#<File:/tmp/RackMultipart20110908-2893-1a8yqe2>>,
 "loc"=>[80.22167450000006,
 13.0454044],
}}

But it was working fine in another form where i manually create the image document like this

params[:images].each do |img|
        image = Image.new(:extension => img.content_type.split('/')[1])
        image.image = img
        @business.images << image
end

I thought carrierwave would take care of this file handling, but i am unsure what is missed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:09:52+00:00Added an answer on May 25, 2026 at 2:09 pm

    The problem is that you need to update the :image attribute defined by the call to mount_uploader, not the Image model in which mount_uploader is called. In other words, you need to update Offer.image.image instead of Offer.image.

    This should work:

       **** snip ****
    
       <div class="ctrlHolder">
        <%= f.fields_for Image.new do |i| %>
          <%= i.label :image, "Image" %>
          <%= i.file_field :image %>
        <%= end %>
        <p class="formHint">Upload image </p>
      </div>
    
      **** snip ****
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problem in getting reference of Ajax control extender using $find() or
I am having this problem uploading PDFs to site. I try it on one
I'm having a problem uploading files on my production server. I'm using the django-stdimage
I'm having an extremely weird problem with a PHP script of mine. I'm uploading
I'm having problem with Rails plugin attachment_fu . On every upload, I get validation
i'm having problem to deal with charset in ruby on rails app, specificially in
I am having a problem with CakePHP 1.3. I'm using a jQuery plugin for
I'm having some difficulties with uploading an image from an html form. The form
I am uploading files and having trouble finding an answer to this question. Some
This is a site we've inherited from someone else. I'am having problems in uploading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.