Path: | lib/features/localized_model_attributes.rb |
Last Update: | Wed Oct 03 19:40:10 +0200 2007 |
Extends ActiveRecord models to provide localized accessors for their attributes. They can simply be used by prefixing the attribute name with localized_. E.g., assuming a model Employee has the attributes birthday, salary and name and the current language is de, the localized attributes can be used like this:
pete = Employee.new(:birthday => Date(1972, 8, 2), :salary => 2200.9, :name => 'Peter') pete.localized_birthday # => "08.02.1972" pete.localized_birthday = "11.03.1980" # => "1980-03-11" pete.localized_salary # => "2.200,9" pete.localized_salary = "3000,50" # => 3000.5
This enables you to use the localized_ attributes in your form helpers, allowing transparent localized input of dates and numbers.
This feature uses the same sections from the lanuage file as do the localized_date_and_time and localized_number_helpers features. For date conversions, the attributes date format from the dates section is used.