Sha256: 9159bdfcd7b654e512bf2d98e072b9d32a2521c45a63ee83d39cb212fed49175

Contents?: true

Size: 823 Bytes

Versions: 1

Compression:

Stored size: 823 Bytes

Contents

require 'template_form/form_builder'

module TemplateForm
  module FormHelper

    def template_form_with(model: false, 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

1 entries across 1 versions & 1 rubygems

Version Path
template_form-0.4.10 lib/template_form/form_helper.rb