Module: ComfyBootstrapForm::ViewHelper

Defined in:
lib/comfy_bootstrap_form/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_form_for(record, options = {}, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/comfy_bootstrap_form/view_helper.rb', line 24

def bootstrap_form_for(record, options = {}, &block)
  options[:html] ||= {}

  bootstrap_options = options[:bootstrap] || {}

  css_classes = options[:html].delete(:class)

  if bootstrap_options[:layout].to_s == "inline"
    css_classes = [css_classes, "form-inline"].compact.join(" ")
  end

  options.reverse_merge!(builder: ComfyBootstrapForm::FormBuilder)
  options[:html].merge!(class: css_classes) unless css_classes.blank?

  supress_form_field_errors do
    form_for(record, options, &block)
  end
end

#bootstrap_form_with(**options, &block) ⇒ Object

Wrapper for ‘form_with`. Passing in Bootstrap form builder.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/comfy_bootstrap_form/view_helper.rb', line 7

def bootstrap_form_with(**options, &block)
  bootstrap_options = options[:bootstrap] || {}

  css_classes = options.delete(:class)

  if bootstrap_options[:layout].to_s == "inline"
    css_classes = [css_classes, "form-inline"].compact.join(" ")
  end

  form_options = options.reverse_merge(builder: ComfyBootstrapForm::FormBuilder)
  form_options.merge!(class: css_classes) unless css_classes.blank?

  supress_form_field_errors do
    form_with(**form_options, &block)
  end
end