Class: ActionView::Helpers::InstanceTag

Inherits:
Object
  • Object
show all
Defined in:
lib/symbolize/symbolize_helper.rb

Instance Method Summary collapse

Instance Method Details

#symbolize_values(choices) ⇒ Object



55
56
57
# File 'lib/symbolize/symbolize_helper.rb', line 55

def symbolize_values(choices)
  choices.nil? ? object.class.send("get_#{@method_name}_values") : choices
end

#to_radio_sym_tag(choices, options) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/symbolize/symbolize_helper.rb', line 36

def to_radio_sym_tag(choices, options)
  choices = symbolize_values(choices)
  raise ArgumentError, "No values for radio tag" unless choices
  add_default_name_and_id(options)
  v = value(object)
  tag_text = ''
  template = options.dup
  template.delete('checked')
  choices.each do |choice|
    opts = template.dup
    opts['checked'] = 'checked' if v and v == choice[1]
    opts['id'] = "#{opts['id']}_#{choice[1]}"
    tag_text << "<label>#{choice[0]}: "
    tag_text << to_radio_button_tag(choice[1], opts)
    tag_text << "</label>"
  end
  tag_text
end

#to_select_sym_tag(choices, options, html_options) ⇒ Object

Create a select tag and one option for each of the symbolize values.



31
32
33
34
# File 'lib/symbolize/symbolize_helper.rb', line 31

def to_select_sym_tag(choices, options, html_options)
  choices = symbolize_values(choices)
  to_select_tag(choices, options, html_options)
end