diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index f4daa6d..d3107df 100644 --- a/lib/enumerated_attribute/integrations/active_record.rb +++ b/lib/enumerated_attribute/integrations/active_record.rb @@ -71,7 +71,7 @@ def []=(attr_name, value); write_enumerated_attribute(attr_name, value); end def attribute=(attr_name, value); write_enumerated_attribute(attr_name, value); end module ClassMethods - def instantiate(record) + def instantiate(record, column_types = {}) object = super(record) self.enumerated_attributes.each do |k,v| unless object.has_attribute?(k) #only initialize the non-column enumerated attributes @@ -103,7 +103,7 @@ def new(*args, &block) result end end - unless private_method_defined?(:method_missing_without_enumerated_attribute) + unless method_defined?(:method_missing_without_enumerated_attribute) || private_method_defined?(:method_missing_without_enumerated_attribute) define_chained_method(:method_missing, :enumerated_attribute) do |method_id, *arguments| arguments = arguments.map{|arg| arg.is_a?(Symbol) ? arg.to_s : arg } method_missing_without_enumerated_attribute(method_id, *arguments) 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