Sha256: 5e30e2f27885bd0253233af2cb0e6637f103c8af1b6337c3cf90c29726c25192

Contents?: true

Size: 821 Bytes

Versions: 4

Compression:

Stored size: 821 Bytes

Contents

require 'template_form/form_builder'

module TemplateForm
  module FormHelper

    def template_form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
      options[:builder] = TemplateForm::FormBuilder
      options[:view] = self

      with_template_form_field_error_proc do
        form_with model: model, scope: scope, url: url, format: format, **options, &block
      end
    end

    private

    def with_template_form_field_error_proc
      default_field_error_proc = ActionView::Base.field_error_proc
      begin
        ActionView::Base.field_error_proc = TemplateForm.field_error_proc
        yield
      ensure
        ActionView::Base.field_error_proc = default_field_error_proc
      end
    end

  end
end

ActiveSupport.on_load(:action_view) do
  include TemplateForm::FormHelper
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
template_form-0.4.9 lib/template_form/form_helper.rb
template_form-0.4.8 lib/template_form/form_helper.rb
template_form-0.4.7 lib/template_form/form_helper.rb
template_form-0.4.6 lib/template_form/form_helper.rb