Forum: Ruby on Rails "humanizing" model attributes presentation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kamil Kukura (Guest)
on 2006-03-08 12:57
(Received via mailing list)
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 J. (Guest)
on 2006-03-08 13:15
(Received via mailing list)
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.
Alain R. (Guest)
on 2006-03-08 14:52
(Received via mailing list)
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
This topic is locked and can not be replied to.