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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:15:33+00:00 2026-06-11T04:15:33+00:00

I have a document Design.rb that has an embedded document Attachment.rb that does some

  • 0

I have a document Design.rb that has an embedded document Attachment.rb that does some validation. If Attachment.rb fails, then the Design.rb should also fail, but it doesn’t.

Any suggestions on how I get my design class to fail if the embedded document fails?

Design.rb:

class Design

    embeds_many :attachments, :as => :attachable

    validates_associated :attachments

    accepts_nested_attributes_for :attachments, :allow_destroy => true

    field :description
    field :title
    field :tags, type: Array
    field :featured, :type => Boolean, :default => false
    field :full_member, :type => Boolean, :default => false
    field :first_design, :type => Boolean, :default => false
    field :option, :type => String 
    field :app_store_url, :type => String 
    field :design_in_progress, :type => Boolean

    attr_accessible :design_in_progress, :tags, :description, :title, :featured, :project_number, :show, :option, :app_store_url, :temp_number, :option, :attachments_attributes

    validates :description, :tags, :title, :presence => true

end

Attachment.rb

require 'carrierwave/mongoid'

class Attachment

    embedded_in :attachable, :polymorphic => true, :inverse_of => :attachments

    field :image
    field :width, :type => Integer
    field :height, :type => Integer
    field :option, :type => String

    attr_accessible :image, :width, :height, :option, :normal, :url

    mount_uploader :image, ImageUploader

    validate :validate_minimum_image_size

    def validate_minimum_image_size
        self.option = self.attachable.option

        case self.option
        when "iphone"
            width = 640
            height = 960
            type = "iPhone"
        when "ipad"
            width = 1536
            height = 2048
            type = "iPad"
        when "icon"
            width = 1024
            height = 1024
            type = "Icon"
        when "wp" 
            width = 480
            height = 800
            type = "Windows Phone"
        when "android"
            width = 480
            height = 800
            type = "Android"
        end

        geometry = self.image.geometry
        unless geometry.nil?
            self.width = geometry[0]
            self.height = geometry[1]
        end

        unless (self.width == width && self.height == height)
            puts "INSIDE ERROR STATEMENT" 
            errors.add :base, "Naughty you... "+type+" designs should be "+width.to_s+"px times "+height.to_s+"px. We want to see your awesome design in retina :-)." 
        end
    end
end
  • 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-06-11T04:15:34+00:00Added an answer on June 11, 2026 at 4:15 am

    You could try adding

    embeds_many :attachments, :as => :attachable, cascade_callbacks: true
    

    Which will call the validations when changes are made through the Design model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have existing java code and need to create Design Document based on that.
I have a document type of info I also have some custom properites. infoTitle
assuming that you have the following sentence in a requirements document The system has
I have a document library in MOSS 2007 which has folders and files. Document
I have a document-based Core Data app. My main Core Data entity has several
I have some code that uses xsl and xml. The Xml control is on
I have come across a website that appears to use Ajax but does not
I am designing a WCF service which have some operations that i expose to
I have a design I'm creating in CSS, and it has started to sort
I have a question that involves a performance question and Mongo Design. Currently a

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.