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



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/enumerated_attribute/rails_helpers.rb', line 52

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] ||= true
    end
  end
  to_select_tag(choices, options, html_options)
end

#to_tag_with_enumerated_attribute(options = {}) ⇒ Object

initialize record_name, method, self



67
68
69
70
71
72
73
74
75
76
# File 'lib/enumerated_attribute/rails_helpers.rb', line 67

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