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 6741317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:42:37+00:00 2026-05-26T11:42:37+00:00

I have two Mongoid models, Store and Product. Their relationship is that a Store

  • 0

I have two Mongoid models, Store and Product. Their relationship is that a Store has_many Products, and Products belongs_to Store. Each of these models has some images that can be attached using Carrierwave, that look like this:

mount_uploader :logo, ImageUploader

I am able to add and edit images that are in the Store model. But in Product I can only add an image on creation off a Product, but not with editing a product. This seems somehow to be a deep_copy issue, similar to how in Mongoid if you have an array called urls and you want to update that array, you must call

urls_will_change!

So I have tried calling the equivalent method (logo_will_change!) inside of a before_update callback, but it doesn’t do anything. Is there somewhere else I should be doing this or is it another problem?

  • 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-26T11:42:38+00:00Added an answer on May 26, 2026 at 11:42 am

    The code below worked for me, so there may be something else going on:

    # store model
    class Store
      include Mongoid::Document
      mount_uploader :image, ImageUploader
      has_many :products
      field :name, type: String
    end
    
    # product model
    class Product
      include Mongoid::Document
      mount_uploader :image, ImageUploader
      belongs_to :store
      field :name, type: String  
    end
    
    # image uploader
    class ImageUploader < CarrierWave::Uploader::Base
      storage :file
      def store_dir
        "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
      end
    end
    
    # some test data
    @store = Store.new({:name => "store"})
    @product = Product.new({:name => "product"})
    @store.save
    @store.products << @product
    
    # later get the product and update the image
    @product = Product.first
    puts @product.image.url # blank
    @product.update_attributes({:image => File.open("/path/to/image.png")})
    puts @product.image.url # now has image url
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Document Models that are proving problematic: class Component include Mongoid::Document include
I have two applications written in Java that communicate with each other using XML
I have two entities, projects and users. These are modeled in Rails using Mongoid
I have got two classes class Claim include Mongoid::Document embeds_many :claim_fields belongs_to :user ...
In this simplified scenario, I have a model called Post Each post has a
Have two events: $('body').mouseup(function(e){} and $('.toggle').click(function(e){} I only want one of these to trigger.
I have two list having many to many relationship. i know how to handle
I have two date picker components and a JComboBox component with their associated Action
I have two BizTalk 2010 servers that belong to the same BizTalk group. They
How can I deal with mongoid documents inside namespaces? I have two mongoid documents

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.