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 ..

class Article
  localized_decimal :price, :tax ...
end

... and I got the two setter and getter methods for free. Anyone have an 
idea how to make it?

Greetings
Benni
-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Railsi18n-discussion mailing list
Railsi18n-discussion@rubyforge.org
http://rubyforge.org/mailman/listinfo/railsi18n-discussion

Reply via email to