Displaying 2 results from an estimated 2 matches for "i_discount_rate".
Did you mean:
discount_rate
2006 Mar 09
1
[TIP] Making an intelligent form fields
...sprintf(''%.2f %%'', value)
end
end
This is an object that takes either float or string (with possible %
character in it) and viewed as string looks like "1.23 %". So I can
easily create an intelligent "shadow" attribute for interaction:
composed_of :i_discount_rate, :class_name => ''Percentage'',
:mapping => %w(discount_rate value)
Using i_discount_rate in form it makes value of discount_rate shown in
text field pretty with % sign. But we cannot pass it to the model
because in mass-assignment everything is just string...
2006 Mar 08
2
"humanizing" model attributes presentation
...ple, 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