Module: BootstrapForm::Helper

Includes:
BootstrapForm::Helpers::NestedForm
Defined in:
lib/bootstrap_form/helper.rb

Instance Method Summary collapse

Instance Method Details

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bootstrap_form/helper.rb', line 7

def bootstrap_form_for(object, options = {}, &block)
  options.reverse_merge!({builder: BootstrapForm::FormBuilder})

  options[:html] ||= {}
  options[:html][:role] ||= 'form'

  layout = case options[:layout]
    when :inline
      "form-inline"
    when :horizontal
      "form-horizontal"
  end

  if layout
    options[:html][:class] = [options[:html][:class], layout].compact.join(" ")
  end

  temporarily_disable_field_error_proc do
    form_for(object, options, &block)
  end
end

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



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

def bootstrap_form_tag(options = {}, &block)
  options[:acts_like_form_tag] = true

  bootstrap_form_for("", options, &block)
end

#temporarily_disable_field_error_procObject



35
36
37
38
39
40
41
# File 'lib/bootstrap_form/helper.rb', line 35

def temporarily_disable_field_error_proc
  original_proc = ActionView::Base.field_error_proc
  ActionView::Base.field_error_proc = proc { |input, instance| input }
  yield
ensure
  ActionView::Base.field_error_proc = original_proc
end