Skip to content

Commit

Permalink
Fixed validation issue in rails 3
Browse files Browse the repository at this point in the history
  • Loading branch information
beerlington committed Oct 19, 2010
1 parent fe90229 commit d3dfb9a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/classy_enum/classy_enum_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def classy_enum_attr(klass, method=nil)
# Add ActiveRecord validation to ensure it won't be saved unless it's an option
self.send(:validates_inclusion_of, method, :in => klass.all)

# Preload the model to prevent validation from failing before a real object is instantiated
self.new(method => nil)

self.instance_eval do

# Define getter method
Expand Down

0 comments on commit d3dfb9a

Please sign in to comment.