Module: HelpfulFields::TagHelper

Defined in:
lib/helpful_fields.rb

Instance Method Summary collapse

Instance Method Details

#check_box_with_label(name, value, checked, label, options = {}) ⇒ Object



40
41
42
43
# File 'lib/helpful_fields.rb', line 40

def check_box_with_label(name, value, checked, label, options={})
  label_for = options[:id] || name
  check_box_tag(name, value, checked, options) + label_tag(label_for, label)
end

#params_check_box_tag(name, value, options = {}) ⇒ Object

— check_box



36
37
38
# File 'lib/helpful_fields.rb', line 36

def params_check_box_tag(name, value, options={})
  check_box_tag(name, value, HelpfulFields.check_box_checked?(params, name, value), options)
end

#params_check_box_with_label(name, value, label, options = {}) ⇒ Object



45
46
47
# File 'lib/helpful_fields.rb', line 45

def params_check_box_with_label(name, value, label, options={})
  check_box_with_label(name, value, HelpfulFields.check_box_checked?(params, name, value), label, options)
end

#params_hidden_field_tag(name, options = {}) ⇒ Object



25
26
27
# File 'lib/helpful_fields.rb', line 25

def params_hidden_field_tag (name, options={})
  hidden_field_tag name, params.value_from_nested_key(name), options
end

#params_radio_button_tag(name, value, options = {}) ⇒ Object



59
60
61
# File 'lib/helpful_fields.rb', line 59

def params_radio_button_tag(name, value, options={})
  radio_button_tag(name, value, HelpfulFields.check_box_checked?(params, name, value), options)
end

#params_radio_button_with_label(name, value, label, options = {}) ⇒ Object



63
64
65
# File 'lib/helpful_fields.rb', line 63

def params_radio_button_with_label(name, value, label, options={})
  radio_button_with_label(name, value, HelpfulFields.check_box_checked?(params, name, value), label, options)
end

#params_select_options_tag(name, list, options = {}) ⇒ Object



29
30
31
32
33
# File 'lib/helpful_fields.rb', line 29

def params_select_options_tag(name, list, options={})
  list = list.map{|x| x.is_a?(Array) ? [x[0],h(x[1])] : h(x) } # stringify values from lists
  selected = h(options[:value] || params.value_from_nested_key(name))
  select_tag(name, options_for_select(list,selected), options.except(:value))
end

#params_text_area_tag(name, options = {}) ⇒ Object



21
22
23
# File 'lib/helpful_fields.rb', line 21

def params_text_area_tag(name, options={})
  text_area_tag name, params.value_from_nested_key(name), options
end

#params_text_field_tag(name, options = {}) ⇒ Object

— misc



17
18
19
# File 'lib/helpful_fields.rb', line 17

def params_text_field_tag(name, options={})
  text_field_tag name, params.value_from_nested_key(name), options
end

#radio_button_with_label(name, value, checked, label, options = {}) ⇒ Object

— radio_button



50
51
52
53
54
55
56
57
# File 'lib/helpful_fields.rb', line 50

def radio_button_with_label(name, value, checked, label, options={})
  label_for = if options[:id]
    options[:id]  # when id was changed, label has to be for this id
  else
    sanitize_to_id(name) + '_' + sanitize_to_id(value)
  end
  radio_button_tag(name, value, checked, :id => label_for) + label_tag(label_for, label)
end