From b09e90ca802bdd1f6df6fa228bf3aeb8ab22d59f Mon Sep 17 00:00:00 2001 From: Rob Chekaluk Date: Sat, 15 Mar 2014 08:21:33 -0400 Subject: [PATCH] Support enum_select in Rails 4 fixes https://github.com/jeffp/enumerated_attribute/issues/67 --- lib/enumerated_attribute/rails_helpers.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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