README.rdoc in enumerate_it-0.5.0 vs README.rdoc in enumerate_it-0.6.0
- old
+ new
@@ -38,11 +38,11 @@
Enter EnumerateIt.
== Creating enumerations
Enumerations are created as models, but you can put then anywhere in your application. In Rails
-applications, I put them inside models/.
+applications, you can put them inside models/.
class RelationshipStatus < EnumerateIt::Base
associate_values(
:single => [1, 'Single'],
:married => [2, 'Married'],
@@ -124,10 +124,21 @@
p = Person.new :relationship_status => 6 # => there is no '6' value in the enumeration
p.valid? # => false
p.errors[:relationship_status] # => "is not included in the list"
+* If your class can manage validations and responds to :validates_presence_of, you can pass the :required options as true and this validation will be created for you (this option defaults to false):
+
+ class Person < ActiveRecord::Base
+ has_enumeration_for :relationship_status, :required => true
+ end
+
+ p = Person.new :relationship_status => nil
+ p.valid? # => false
+ p.errors[:relationship_status] # => "can't be blank"
+
+
Remember that in Rails 3 you can add validations to any kind of class and not only to those derived from
ActiveRecord::Base.
== I18n
@@ -167,9 +178,17 @@
* Create an initializer with the following code:
ActiveRecord::Base.send :include, EnumerateIt
* Add the 'enumerate_it' gem as a dependency in your environment.rb (Rails 2.3.x) or Gemfile (if you're using Bundler)
+
+An interesting approach to use it in Rails apps is to create an app/models/enumerations folder and add it to your autoload path in config/application.rb:
+
+ module YourApp
+ class Application < Rails::Application
+ config.autoload_paths << "#{Rails.root}/app/models/enumerations"
+ end
+ end
== Ruby 1.9
EnumerateIt is fully compatible with Ruby 1.9.1 (all tests pass)