Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/enumerated_attribute/integrations/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions lib/enumerated_attribute/rails_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down