Given a field in database defined as "discount_rate numeric(3,1)" I found it not very usable for presenting it directly. For example, if there's a value 5.00 it will render in <%= text_field 'model', 'discount_rate %> as "0.5E1" which is not very friendly to user. All I do is that I write kind of proxy accessors (prefixing with i_) for handling these situations: def i_discount_rate sprintf('%.2f', discount_rate) end def i_discount_rate=(value) self.discount_rate = value end Is there a better way for handling this? Having a bunch of input fields makes the model fairly bigger in size. -- Kamil
on 2006-03-08 12:57
on 2006-03-08 13:15
Kamil Kukura wrote: > Is there a better way for handling this? Having a bunch of input fields > makes the model fairly bigger in size. A simple patch to actionpack to add a :format option to text_field and text_field_tag would be the best solution. -- We develop, watch us RoR, in numbers too big to ignore.
on 2006-03-08 14:52
Next to what Mark said, a member of this forum is working on an "object rendering" solution (Look in the archive for the thread titled "Teaching Models to Render Themselves in the Controller" Alain