Class: GenericFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/generic_form_builder.rb

Instance Method Summary collapse

Instance Method Details

#buttons(options = {}) ⇒ Object



62
63
64
65
66
67
# File 'lib/generic_form_builder.rb', line 62

def buttons(options = {})
  buttons  = (:button, (:span, options[:submit_text] || 'Save'), :type => 'submit')
  buttons << link_to('Cancel', options[:cancel_link], :class => 'cancel button') if options[:cancel_link]

  (:div, buttons, :class => 'actions')
end

#check_box(field, options = {}) ⇒ Object



48
49
50
51
52
53
# File 'lib/generic_form_builder.rb', line 48

def check_box(field, options = {})
  return super if options[:default_builder]
  label_text = options[:label] || field.to_s.humanize
  note       = note_html(options[:note])
  (:p, label(field, super + " #{label_text} #{errors_text(field)}".try(:html_safe) + note, :class => 'checkbox'))
end

#collection_select(field, collection, value_method, name_method, options = {}, html_options = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/generic_form_builder.rb', line 41

def collection_select(field, collection, value_method, name_method, options = {}, html_options = {})
  return super(field, collection, value_method, name_method) if options[:default_builder]
  label_text = options[:label] || field.to_s.humanize
  note       = note_html(options[:note])
  (:p, label(field, "#{label_text} #{errors_text(field)}".try(:html_safe)) + note + super(field, collection, value_method, name_method))
end

#radio_button(field, value, options = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/generic_form_builder.rb', line 55

def radio_button(field, value, options = {})
  return super if options[:default_builder]
  label_text = options.delete(:label) || field.to_s.humanize
  tag_type = options.delete(:tag_type) || :li
  (tag_type, label("#{field}_#{value.to_s.downcase.gsub(' ', '_')}", super + " #{label_text} #{errors_text(field)}".try(:html_safe), :class => 'radio', :onclick => ""))
end

#select(field, collection, options = {}, html_options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/generic_form_builder.rb', line 30

def select(field, collection, options = {}, html_options = {})
  return super if options[:default_builder]
  label_text = options[:label] || field.to_s.humanize
  note       = note_html(options[:note])
  p_html_options = {}
  if any_errors?(field)
    p_html_options.merge!('class' => 'errors')
  end
  (:p, label(field, "#{label_text} #{errors_text(field)}".try(:html_safe)) + note + super, p_html_options)
end