Class: ActionView::Helpers::InstanceTag

Inherits:
Object
  • Object
show all
Defined in:
lib/enumerated_attribute/rails_helpers.rb

Instance Method Summary collapse

Instance Method Details

#to_enum_select_tag(options, html_options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/enumerated_attribute/rails_helpers.rb', line 60

def to_enum_select_tag(options, html_options={})
  choices = []
  if self.object.respond_to?(:enums)
    enums = self.object.enums(method_name.to_sym)
    choices = enums ? enums.select_options : []
    if (value = self.object.__send__(method_name.to_sym))
      options[:selected] ||= value.to_s
    else
          options[:include_blank] = enums.allows_nil? if options[:include_blank].nil?
    end
  end
  to_select_tag(choices, options, html_options)
end

#to_tag_with_enumerated_attribute(options = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/enumerated_attribute/rails_helpers.rb', line 76

def to_tag_with_enumerated_attribute(options={})
  #look for an enum
  if (column_type == :string && 
    self.object.class.respond_to?(:has_enumerated_attribute?) &&
    self.object.class.has_enumerated_attribute?(method_name.to_sym)) 
    to_enum_select_tag(options)
  else
    to_tag_without_enumerated_attribute(options)
  end
end