Class: ActionView::Helpers::InstanceTag

Inherits:
Object
  • Object
show all
Defined in:
lib/enum/active_record_helper.rb

Instance Method Summary collapse

Instance Method Details

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



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/enum/active_record_helper.rb', line 28

def to_enum_select_tag(options, html_options={})
  if self.object.respond_to?(method_name.to_sym)
    column = self.object.column_for_attribute(method_name)
    if (value = self.object.__send__(method_name.to_sym))
      options[:selected] ||= value.to_s
    else
      options[:include_blank] = column.null if options[:include_blank].nil?
    end
  end
  to_select_tag(column.limit, options, html_options)
end

#to_tag_with_enumerated_attribute(options = {}) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/enum/active_record_helper.rb', line 42

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