diff --git a/lib/enumerated_attribute/rails_helpers.rb b/lib/enumerated_attribute/rails_helpers.rb index 80e8397..9a7bcda 100644 --- a/lib/enumerated_attribute/rails_helpers.rb +++ b/lib/enumerated_attribute/rails_helpers.rb @@ -64,7 +64,19 @@ module Helpers module FormOptionsHelper #def select def enum_select(object, method, options={}, html_options={}) + if defined?(ActionView::Base::Tags::Select) # Rails 4 + select_tag = Tags::Select.new(object, method, self, [], options, html_options) + obj = select_tag.object + + choices = [] + if obj.respond_to?(:enums) + enums = obj.enums(method.to_sym) + choices = enums ? enums.select_options : [] + end + Tags::Select.new(object, method, self, choices, options, html_options).render + else # Rails 3 InstanceTag.new(object, method, self, options.delete(:object)).to_enum_select_tag(options, html_options) + end end end