Displaying 4 results from an estimated 4 matches for "price_in_euros".
2006 Jun 07
2
Problem with a setter that converts euros to cents
...sors to do currency conversions. In my model, I have a price
attribute in the database that stores the value in cents, to avoid
future problems with float arithmetic and round. But at the views, I
would like to show the price in euros, with decimal for the cents. So
I defined a new attribute called price_in_euros, and the corresponding
accesors:
class Report < ActiveRecord::Base
validates_numericality_of :price, :only_integer => true
attr_accessor :price_in_euros
def price_in_euros
if self.price
self.price / 100.0
else
# default price is 1 euro
1
end
end
def price_in_euros=(eur...
2006 Jun 07
1
Setter that converts a float attribute to integer
...sors to do currency conversions. In my model, I have a price
attribute in the database that stores the value in cents, to avoid
future problems with float arithmetic and round. But at the views, I
would like to show the price in euros, with decimal for the cents. So
I defined a new attribute called price_in_euros, and the corresponding
accesors:
class Report < ActiveRecord::Base
validates_numericality_of :price, :only_integer => true
attr_accessor :price_in_euros
def price_in_euros
if self.price
self.price / 100.0
else...
2005 Dec 23
10
Extending model
Hi,
I''m looking for a way to extend one of my models to allow some level
of abstraction between what goes into it and how it is stored.
For example, say I have a Product and I want to set it''s price. A
person using the website will type the price in euros. Internally, I''d
like to store the price as an integer value of cents.
I can currently do this with some ugly code
2006 Jul 04
8
inherits_from: Multiple table inheritance
Hey guys,
I just implemented very simple and primitive class table inheritance in
ActiveRecord. The goal is for this to become mature enough to become a
true feature in Rails. Check it out here:
http://guest@blog.raylucke.com/svn/inherits_from
Here?s how it looks in action:
create_table "books", :force => true do |t|
t.column "product_id", :integer
t.column