Sha256: a581d8bf62305815d662e32fa535277a869c4c48cd6308894668a8aa55ac82f2

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

class Product < ActiveRecord::Base

  attr_accessible :price_cents, :discount, :bonus_cents,
    :price, :discount_value, :bonus, :optional_price_cents, :optional_price,
    :sale_price, :sale_price_amount, :sale_price_currency_code,
    :price_in_a_range_cents, :price_in_a_range, :invalid_price_cents

  # Use USD as model level currency
  register_currency :usd

  # Use money-rails macros
  monetize :price_cents

  # Use a custom name for the Money attribute
  monetize :discount, :as => "discount_value"

  # Allow nil
  monetize :optional_price_cents, :allow_nil => true

  # Override default currency (EUR) with a specific one (GBP) for this field only
  monetize :bonus_cents, :with_currency => :gbp

  # Use currency column to determine currency for this field only
  monetize :sale_price_amount, :as => :sale_price,
             :with_model_currency => :sale_price_currency_code

  monetize :price_in_a_range_cents, :allow_nil => true,
    :subunit_numericality => {
      :greater_than => 0,
      :less_than_or_equal_to => 10000,
    },
    :numericality => {
      :greater_than => 0,
      :less_than_or_equal_to => 100,
      :message => "Must be greater than zero and less than $100"
    }

  attr_accessor :invalid_price_cents
  monetize :invalid_price_cents, disable_validation: true

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
money-rails-0.9.0 spec/dummy/app/models/product.rb