module BootstrapForm::ActionViewExtensions::FormHelper

This module creates BootstrapForm wrappers around the default form_with and form_for methods

Example:

bootstrap_form_for @user do |f|
  f.text_field :name
end

Example:

bootstrap_form_with model: @user do |f|
  f.text_field :name
end

Public Instance Methods

bootstrap_form_for(record, options={}, &block) click to toggle source
# File lib/bootstrap_form/action_view_extensions/form_helper.rb, line 20
def bootstrap_form_for(record, options={}, &block)
  options.reverse_merge!(builder: BootstrapForm::FormBuilder)

  with_bootstrap_form_field_error_proc do
    form_for(record, options, &block)
  end
end
bootstrap_form_tag(options={}, &block) click to toggle source
# File lib/bootstrap_form/action_view_extensions/form_helper.rb, line 36
def bootstrap_form_tag(options={}, &block)
  options[:acts_like_form_tag] = true

  bootstrap_form_for("", options, &block)
end
bootstrap_form_with(options={}, &block) click to toggle source
# File lib/bootstrap_form/action_view_extensions/form_helper.rb, line 28
def bootstrap_form_with(options={}, &block)
  options.reverse_merge!(builder: BootstrapForm::FormBuilder)

  with_bootstrap_form_field_error_proc do
    form_with(**options, &block)
  end
end

Private Instance Methods

with_bootstrap_form_field_error_proc() { || ... } click to toggle source
# File lib/bootstrap_form/action_view_extensions/form_helper.rb, line 44
def with_bootstrap_form_field_error_proc
  original_proc = ActionView::Base.field_error_proc
  ActionView::Base.field_error_proc = BootstrapForm.field_error_proc
  yield
ensure
  ActionView::Base.field_error_proc = original_proc
end