Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

document dirty attributes option, fixes #24

  • Loading branch information...
commit d3cdbf21029859050a42e8f20375dd754fdbfc0a 1 parent 65b2058
@lwe authored
Showing with 16 additions and 4 deletions.
  1. +16 −4 README.rdoc
View
20 README.rdoc
@@ -97,6 +97,18 @@ useful when creating queries, displaying option elements or similar:
as_enum :gender, [:male, :female], :column => 'sex'
end
+* Want support for ActiveRecords dirty attributes, provide <tt>:dirty => true</tt> as option, which automatically adds both
+ the <tt>{enum}_changed?</tt> and <tt>{enum}_was</tt> methods, which delegate to ActiveRecord.
+
+ class User < ActiveRecord::Base
+ as_enum :gender, [:male, :female], :dirty => true
+ end
+
+ @user = User.where(:gender_cd => User.male).first
+ @user.gender = :female
+ @user.gender_was
+ # => :male
+
* Need to provide custom options for the mongoid field, or skip the automatically generated field?
# skip field generation
@@ -106,10 +118,6 @@ useful when creating queries, displaying option elements or similar:
# custom field options (directly passed to Mongoid::Document#field)
as_enum :gender, [:male, :female], :field => { :type => Integer, :default => 1 }
-* To make it easier to create dropdowns with values use:
-
- <%= select(:user, :gender, User.genders.keys) %>
-
* It's possible to validate the internal enum values, just like any other ActiveRecord validation:
class User < ActiveRecord::Base
@@ -172,6 +180,10 @@ useful when creating queries, displaying option elements or similar:
as_enum :gender, [:male, :female], :whiny => false
end
+* To make it easier to create dropdowns with values use:
+
+ <%= select(:user, :gender, User.genders.keys) %>
+
* Need translated keys et al in your forms? SimpleEnum provides a <tt><enum>_for_select</tt> method:
# on the gender field
Please sign in to comment.
Something went wrong with that request. Please try again.