Module: Formulate::FormHelper

Defined in:
lib/formulate/form_helper.rb

Constant Summary collapse

FIELD_ERROR_PROC =
proc { |html_tag, instance_tag| html_tag }

Instance Method Summary collapse

Instance Method Details

#form_for(record, options = {}, &proc) ⇒ Object



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

def form_for(record, options={}, &proc)
  options[:html] ||= {}
  options[:builder] ||= FormBuilder

  case record
  when String, Symbol
    options[:html][:class] ||= ''
  else
    object = record.is_a?(Array) ? record.last : record
    raise ArgumentError, 'First argument in form cannot contain nil or be empty' unless object
    apply_form_for_options!(record, object, options)
  end

  options[:html][:class] << ' formulate'
  options[:html][:class] << " #{options[:class]}" if options[:class]
  options[:html][:class].strip!

  original_field_error_proc = ::ActionView::Base.field_error_proc
  ::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
  super
ensure
  ::ActionView::Base.field_error_proc = original_field_error_proc
end