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
Mark Reginald James
2006-Mar-08 11:13 UTC
[Rails] Re: "humanizing" model attributes presentation
Kamil Kukura wrote:> 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: > ... > > 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.