README.rdoc in enumerate_it-0.4.0 vs README.rdoc in enumerate_it-0.5.0
- old
+ new
@@ -45,11 +45,11 @@
class RelationshipStatus < EnumerateIt::Base
associate_values(
:single => [1, 'Single'],
:married => [2, 'Married'],
:widow => [3, 'Widow'],
- :divorced => [4, 'Divorced'],
+ :divorced => [4, 'Divorced']
)
end
This will create some nice stuff:
@@ -126,9 +126,38 @@
p.valid? # => false
p.errors[:relationship_status] # => "is not included in the list"
Remember that in Rails 3 you can add validations to any kind of class and not only to those derived from
ActiveRecord::Base.
+
+== I18n
+
+I18n lookup is provided on both '_humanized' and 'Enumeration#to_a' methods, given the hash key is a Symbol. The I18n strings are
+located on enumerations.'enumeration_name'.'key' :
+
+ class RelationshipStatus < EnumerateIt::Base
+ associate_values(
+ :married => 1,
+ :single => 2,
+ :divorced => [3, 'He's divorced']
+ )
+ end
+
+ # your locale file
+ pt:
+ enumerations:
+ relationship_status:
+ single: Casado
+
+ p = Person.new
+ p.relationship_status = RelationshipStatus::MARRIED
+ p.relationship_status_humanize # => 'Casado'
+
+ p.relationship_status = RelationshipStatus::SINGLE
+ p.relationship_status_humanize # => 'Single' => nonexistent key
+
+ p.relationship_status = RelationshipStatus::DIVORCED
+ p.relationship_status_humanize # => 'He's divorced' => uses the provided string
== Installation
gem install enumerate_it