Class: ActionView::Helpers::FormBuilder
- Inherits:
-
Object
- Object
- ActionView::Helpers::FormBuilder
- Includes:
- Context, TagHelper
- Defined in:
- lib/form_builder.rb
Instance Method Summary collapse
- #bs_static_control(method) ⇒ Object
- #form_group(method = nil, options = {}, &block) ⇒ Object
- #label(method, text = nil, options = {}, &block) ⇒ Object
- #validation_error(method) ⇒ Object
Instance Method Details
#bs_static_control(method) ⇒ Object
83 84 85 |
# File 'lib/form_builder.rb', line 83 def bs_static_control(method) content_tag :p, @object.send(method), class: 'form-control-static' end |
#form_group(method = nil, options = {}, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/form_builder.rb', line 11 def form_group(method=nil, ={}, &block) raise ArgumentError, 'Missing block' unless block_given? method, = nil, method if method.is_a? Hash = .dup classes = parse_html_classes_to_arr [:class] add_html_class classes, 'form-group' [:class] = classes bs_form_helper = BsFormBuilder.new self, @object_name, method content = @template.capture(bs_form_helper, &block) if method if @object.errors[method].any? add_html_class classes, 'has-error' end if render_validation_error? content << validation_error(method) end end content_tag :div, content, end |
#label(method, text = nil, options = {}, &block) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/form_builder.rb', line 63 def label(method, text = nil, = {}, &block) if text.is_a? Hash label_text = nil = text.dup else label_text = text = .dup end label_classes = parse_html_classes_to_arr [:class] if @object.class.validators_on(method).map(&:class).include?(ActiveRecord::Validations::PresenceValidator) add_html_class label_classes, 'required-label' end [:class] = label_classes @template.label @object_name, method, label_text, , &block end |
#validation_error(method) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/form_builder.rb', line 36 def validation_error(method) if @object.errors[method].any? errors = @object.errors[method].join(' ') content_tag(:span, errors, class: [:'helper-block', :'text-danger']) end end |