From 33c4ab670f878be91978eebc0a114b1ce68bf705 Mon Sep 17 00:00:00 2001 From: Rob Chekaluk Date: Thu, 16 Jan 2014 17:33:02 -0500 Subject: [PATCH 1/3] Prevent "circular references" error by error checking similar to meta_programming gem. --- lib/enumerated_attribute/integrations/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index f4daa6d..04399f4 100644 --- a/lib/enumerated_attribute/integrations/active_record.rb +++ b/lib/enumerated_attribute/integrations/active_record.rb @@ -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) From 524f2f142b34b8f3c05d3d1b0910e7f0e5579936 Mon Sep 17 00:00:00 2001 From: Rob Chekaluk Date: Sun, 23 Feb 2014 08:19:01 -0500 Subject: [PATCH 2/3] Rails 4; permit 2 arguments to ActiveRecord::Persistence::ClassMethods. Supports https://github.com/jeffp/enumerated_attribute/issues/66 --- lib/enumerated_attribute/integrations/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index 04399f4..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 From b09e90ca802bdd1f6df6fa228bf3aeb8ab22d59f Mon Sep 17 00:00:00 2001 From: Rob Chekaluk Date: Sat, 15 Mar 2014 08:21:33 -0400 Subject: [PATCH 3/3] 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