Class: GenericFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- GenericFormBuilder
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/generic_form_builder.rb
Constant Summary collapse
- STANDARD_FIELDS =
%w[ text_field password_field text_area email_field file_field number_field date_field ].freeze
Instance Method Summary collapse
- #buttons(options = {}) ⇒ Object
- #check_box(field, options = {}) ⇒ Object
- #collection_select(field, collection, value_method, name_method, options = {}, html_options = {}) ⇒ Object
- #radio_button(field, value, options = {}) ⇒ Object
- #select(field, collection, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#buttons(options = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/generic_form_builder.rb', line 69 def ( = {}) = { cancel_class: ["cancel", "button"], wrapper_class: ["actions"] }.merge() = content_tag(:button, content_tag(:span, [:submit_text] || 'Save'), type: 'submit', class: [:button_class] ) << link_to('Cancel', [:cancel_link], class: [:cancel_class]) if [:cancel_link] content_tag(:div, , class: [:wrapper_class]) end |
#check_box(field, options = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/generic_form_builder.rb', line 55 def check_box(field, = {}) return super if [:default_builder] label_text = [:label] || field.to_s.humanize note = note_html([:note]) content_tag(: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
48 49 50 51 52 53 |
# File 'lib/generic_form_builder.rb', line 48 def collection_select(field, collection, value_method, name_method, = {}, = {}) return super(field, collection, value_method, name_method) if [:default_builder] label_text = [:label] || field.to_s.humanize note = note_html([:note]) content_tag(: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
62 63 64 65 66 67 |
# File 'lib/generic_form_builder.rb', line 62 def (field, value, = {}) return super if [:default_builder] label_text = .delete(:label) || field.to_s.humanize tag_type = .delete(:tag_type) || :li content_tag(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
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/generic_form_builder.rb', line 37 def select(field, collection, = {}, = {}) return super if [:default_builder] label_text = [:label] || field.to_s.humanize note = note_html([:note]) = .delete(:wrapper_html_options) || {} if any_errors?(field) .merge!('class' => 'errors') end content_tag(:p, label(field, "#{label_text} #{errors_text(field)}".try(:html_safe)) + note + super, ) end |