On 2.7.2008, at 21.00, Benjamin Meichsner wrote:
Hey Jarkko, thanks for your comment. I give it another try: # the extensions class String def to_delocalized_decimal BigDecimal.new(self.sub(',', '.')) rescue self end end class BigDecimal def to_localized_string(precision=2) ("%01.#{precision}f" % self).to_s.sub('.', ',') rescue self.to_s end end # my ActiveRecord-Class class Article < ActiveRecord::Base def localized_price=(value) self.price = value.to_delocalized_decimal unless value.blank? end def localized_price price.to_localized_string if price end end # my new.html.erb ... <b>Price</b><br /> <%= f.text_field :localized_price %> But I guess, you have a solution more elegant? I'm dreaming of an ActiveRecordPlugin, so I just have to write ..
Sorry, I've just used a before_save filter defined in AR::Base. It would be fairly easy to make a plugin out of that, all it takes is some metaprogramming skills. If you aren't familiar with metaprogramming in Ruby, I highly recommend PragDave's recent screencasts (http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming ). They'll cost you $5 a piece, but with the current state of the dollar that's not too much asked imho.
Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Railsi18n-discussion mailing list Railsi18n-discussion@rubyforge.org http://rubyforge.org/mailman/listinfo/railsi18n-discussion