Displaying 2 results from an estimated 2 matches for "cubits_to_inches".
2006 Aug 01
0
Validation of facade columns
...ns. For some unknown reason,
width is stored in inches and length is stored in cubits. Since I want
the model to expose both measurements in inches, I''ve made length a
facade column as discussed in AWDR:
class Rectangle < ActiveRecord::Base
validates_numericality_of :width, :length
CUBITS_TO_INCHES = 18
def length
read_attribute("length") * CUBITS_TO_INCHES
end
def length=(inches)
write_attribute("length", Float(inches) / CUBITS_TO_INCHES)
end
end
Now let''s skip to the controller, and try to validate bogus length and
width values submitted from text fie...
2006 Aug 19
5
Form helpers don''t work with facade columns?
Hello all,
I''ve been trying to use a facade column but I notice that the form
helpers don''t seem to respect the facade.
In the following example I''m trying to story the prices as Integer
values but present them to the user as decimals.
class Product < ActiveRecord::Base
def price=(new_price)
write_attribute(:price, Float(new_price)*100)
end
def price