Skip to content

Commit

Permalink
Support enum_select in Rails 4 fixes jeffp#67
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Chekaluk committed Mar 15, 2014
1 parent 524f2f1 commit b09e90c
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit b09e90c

Please sign in to comment.