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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:01:37+00:00 2026-06-10T03:01:37+00:00

Please consider two objects of class Product: class Product < ActiveRecord::Base { :id =>

  • 0

Please consider two objects of class Product:

class Product < ActiveRecord::Base {
  :id => :integer,
  :name => :string,
  :total_stock => :integer,
  :cents_retail_sale_amount => :integer,
  :cents_cost_amount => :integer,
  :created_at => :datetime,
  :updated_at => :datetime
}

Let’s say I have 2 objects:

  a{
  :id => 12,
  :name => "Shirt",
  :total_stock => 1,
  :cents_retail_sale_amount => 2500,
  :cents_cost_amount => 2100,
  :created_at => Mon, 23 Jul 2012 16:16:33 CDT -05:00,
  :updated_at => Mon, 23 Jul 2012 17:24:15 CDT -05:00}

  b {
  :id => nil,
  :name => "Polo Shirt",
  :total_stock => 1,
  :cents_retail_sale_amount => 2500,
  :cents_cost_amount => 2100,
  :created_at => Mon, 23 Jul 2012 16:16:33 CDT -05:00,
  :updated_at => Mon, 23 Jul 2012 17:24:15 CDT -05:00}

Now here is what I’m trying to do:

a.update_attributes(b.to_product.attributes.except("id", "created_at", "updated_at")

The problem however ( which I caught only cause I have a validation on the cents fields – to allow amounts only between 0 and $100 ( 10000 cents)), is this – my cents fields get also updated and get extra 00 at the end – so I get $2500 & $2100 for the the retail and cost amounts. While really nice profit margin – not really realistic.

I can obviously do some kind of processing on the b object before updating attributes ( such as not updating money fields and do the separately one by one), but that’s not really efficient. So I’m wondering if I’m doing something wrong

Thanks

  • 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-10T03:01:39+00:00Added an answer on June 10, 2026 at 3:01 am

    I switched to https://github.com/RubyMoney/money-rails gem instead which solved the issue

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

Sidebar

Related Questions

Please consider the two snippets of code (notice the distinction between string and integer):
Please consider the following two entities: @Entity @Table(name = PROFILE) public class Profile extends
Please consider the following code: public class Person ( public string FirstName {get; set;}
I am trying to replace one or two letters in a string. Please consider
Please clarify my doubt in Hashset. Consider the following code, class Person { String
Please consider such scenerio: I have component called TMenuItemSelector which has two published properties:
I have doubt with android backstack , please consider the scenario I have two
please consider this code : 1)public static class MyClass 2){ 3) public static DateTime
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
Please consider the two snippets of code (the first prints Local eval, the second

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.