Vadim B
Vadim B

Reputation: 73

Override the values in the method

I have an online store. There is a column price(using the gem money). And there is a column "discount". And if the store Manager records the price in column "discount", the store needs to display the price(column "discount") I Think that I need to override "price" in the model. but I don't know how to access the column "price"?

class Item < ActiveRecord::Base
  monetize :price_cents
  monetize :discount_cents


  def price
    if self.discount > 0
      self.discount
    else
      ?
      If I call, 
      self.price
      it turns out called once again this method.
      self[:price]
      = nil, why?
    end
  end
end

Upvotes: 0

Views: 64

Answers (1)

mswiszcz
mswiszcz

Reputation: 1006

super may work, or consider using decorators for this kind of stuff.

Upvotes: 1

Related Questions