Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4 support #68

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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