I've just started with Hobo about a week ago and I'm really enjoying
it. It definitely makes vanilla Rails seem like hard work.
I was wondering if there are plans to extend the rich fields system. I
see at present it supports validation and representation to HTML but
it doesn't seem to support conversion for storage.
An example would be currency. I want to store an amount of money in
cents but allow it to be entered and display it in a (culturally
insensitive) dollars.cents format. I can convert it in the model by
overriding the attribute accessors for it:
fields do
price :integer
end
def price() self[:price].as_dollars_and_cents; end
def price=(dollars) self[:price]=convert_to_cents(dollars); end
By writing a Rails initializer (http://pastie.org/504098), I can get it down to:
fields do
price :integer
end
treat_as_currency :price
But what would be really cool would be to get it down to:
fields do
price :currency
end
Any thoughts on how/whether this could/should be achieved?
Thanks
Ritchie
I think hobo-contrib is an excellent place for something like that.
cheers,
Bryan
What I've done is just define a separate table. IE,
EstimatedBigDecimal is stored in the estimated_big_decimals table, and
classes that use it have `belongs_to :price, :class =>
"EstimatedBigDecimal"`.
It seems wrong, but it works smoothly and allows me to define a custom
view, custom input, et cetera for it.
Now granted, my classes weren't quite as simple as EstimatedBigDecimal,
but simple enough that a separate table certainly seemed questionable!
cheers,
Bryan