Class: ActionView::Helpers::InstanceTag
- Inherits:
-
Object
- Object
- ActionView::Helpers::InstanceTag
- Defined in:
- lib/enum_column/active_record_helper.rb
Overview
:nodoc:
Instance Method Summary collapse
- #__to_tag_enum ⇒ Object
-
#enum_values ⇒ Object
Gets the list of values for the column.
-
#to_enum_radio_tag(options = {}) ⇒ Object
Creates a set of radio buttons and labels.
-
#to_enum_select_tag(options = {}) ⇒ Object
Create a select tag and one option for each of the enumeration values.
-
#to_tag(options = {}) ⇒ Object
Add the enumeration tag support.
Instance Method Details
#__to_tag_enum ⇒ Object
38 |
# File 'lib/enum_column/active_record_helper.rb', line 38 alias __to_tag_enum to_tag |
#enum_values ⇒ Object
Gets the list of values for the column.
102 103 104 |
# File 'lib/enum_column/active_record_helper.rb', line 102 def enum_values object.send("column_for_attribute", @method_name).values end |
#to_enum_radio_tag(options = {}) ⇒ Object
Creates a set of radio buttons and labels.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/enum_column/active_record_helper.rb', line 77 def to_enum_radio_tag( = {}) # Remove when we no longer support 1.1. begin v = value(object) rescue ArgumentError v = value end add_default_name_and_id() values = enum_values raise ArgumentError, "No values for enum select tag" unless values tag_text = '' template = .dup template.delete('checked') values.each do |enum| opts = template.dup opts['checked'] = 'checked' if v and v == enum opts['id'] = "#{opts['id']}_#{enum}" tag_text << "<label>#{enum}: " tag_text << (enum, opts) tag_text << "</label>" end tag_text end |
#to_enum_select_tag(options = {}) ⇒ Object
Create a select tag and one option for each of the enumeration values.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/enum_column/active_record_helper.rb', line 52 def to_enum_select_tag( = {}) # Remove when we no longer support 1.1. begin v = value(object) rescue ArgumentError v = value end add_default_name_and_id() tag_text = "<select" tag_text << () tag_text << ">" values = enum_values raise ArgumentError, "No values for enum select tag" unless values if [:include_blank] tag_text << "<option value=\"\"></option>\n" end values.each do |enum| tag_text << "<option value=\"#{enum}\"" tag_text << ' selected="selected"' if v and v == enum tag_text << ">#{enum}</option>" end tag_text << "</select>" end |
#to_tag(options = {}) ⇒ Object
Add the enumeration tag support. Defaults using the select tag to display the options.
42 43 44 45 46 47 48 |
# File 'lib/enum_column/active_record_helper.rb', line 42 def to_tag( = {}) if column_type == :enum to_enum_select_tag() else __to_tag_enum() end end |