Skip to content
Browse files

Updated helper

  • Loading branch information...
1 parent 4591141 commit 8afc75790eb1d6c54f3e9e2a863a16408d6ab632 @glennpow committed
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/active_enumeration/enumeration_helper.rb
View
11 lib/active_enumeration/enumeration_helper.rb
@@ -12,8 +12,15 @@ def enumeration_select(form_or_record, name, options = {}, html_options = {})
enumeration_foreign_key = options.delete(:enumeration_foreign_key)
enumeration_class = options.delete(:enumeration_class)
- if (enumeration_foreign_key.nil? || enumeration_class.nil?) && form_or_record.object
- record_class = form_or_record.object.class
+ record = case form_or_record
+ when ActionView::Helpers::FormBuilder
+ form_or_record.object
+ else
+ form_or_record
+ end
+
+ if (enumeration_foreign_key.nil? || enumeration_class.nil?) && record
+ record_class = record.class
if record_class.respond_to?(:reflect_on_enumeration) && reflection = record_class.reflect_on_enumeration(name)
enumeration_foreign_key ||= reflection.foreign_key
enumeration_class ||= reflection.klass

0 comments on commit 8afc757

Please sign in to comment.
Something went wrong with that request. Please try again.