Module: Trestle::FormHelper

Defined in:
app/helpers/trestle/form_helper.rb

Constant Summary collapse

IDENTITY_FIELD_ERROR_PROC =
Proc.new { |html_tag, instance| html_tag }
DEFAULT_FORM_CONTROLLERS =
%w(keyboard-submit form-loading form-error)

Instance Method Summary collapse

Instance Method Details

#formObject



36
37
38
# File 'app/helpers/trestle/form_helper.rb', line 36

def form
  @_trestle_form
end

#render_sidebar_as_tab?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/helpers/trestle/form_helper.rb', line 44

def render_sidebar_as_tab?
  modal_request? && content_for?(:sidebar)
end


40
41
42
# File 'app/helpers/trestle/form_helper.rb', line 40

def sidebar(&block)
  content_for(:sidebar, &block)
end

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



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/trestle/form_helper.rb', line 6

def trestle_form_for(instance, options={}, &block)
  options[:builder] ||= Form::Builder
  options[:as] ||= admin.parameter_name

  options[:data] ||= {}
  options[:data][:controller] = (DEFAULT_FORM_CONTROLLERS + Array(options[:data][:controller])).join(" ")

  form_for(instance, options) do |f|
    with_identity_field_error_proc do
      with_form(f) { yield f }
    end
  end
end

#with_form(form) ⇒ Object



20
21
22
23
24
25
# File 'app/helpers/trestle/form_helper.rb', line 20

def with_form(form)
  @_trestle_form = form
  yield form if block_given?
ensure
  @_trestle_form = nil
end

#with_identity_field_error_procObject



27
28
29
30
31
32
33
34
# File 'app/helpers/trestle/form_helper.rb', line 27

def with_identity_field_error_proc
  original_field_error_proc = ::ActionView::Base.field_error_proc
  ::ActionView::Base.field_error_proc = IDENTITY_FIELD_ERROR_PROC

  yield if block_given?
ensure
  ::ActionView::Base.field_error_proc = original_field_error_proc
end