Module: GenericFormFor::Helpers::FormHelper

Included in:
FormBuilder
Defined in:
lib/generic_form_for/helpers/form_helper.rb

Overview

FormHelper is a wrapper around Rails’ built-in form helper

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args.



9
10
11
# File 'lib/generic_form_for/helpers/form_helper.rb', line 9

def args
  @args
end

#autofocusObject

Returns the value of attribute autofocus.



8
9
10
# File 'lib/generic_form_for/helpers/form_helper.rb', line 8

def autofocus
  @autofocus
end

#procObject

Returns the value of attribute proc.



9
10
11
# File 'lib/generic_form_for/helpers/form_helper.rb', line 9

def proc
  @proc
end

#recordObject

Returns the value of attribute record.



9
10
11
# File 'lib/generic_form_for/helpers/form_helper.rb', line 9

def record
  @record
end

Instance Method Details

#generic_fields_for(name, *args, &proc) ⇒ Object



26
27
28
29
30
# File 'lib/generic_form_for/helpers/form_helper.rb', line 26

def generic_fields_for(name, *args, &proc)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options[:builder] ||= GenericFormFor::FormBuilder
  fields_for(name, *(args << options), &proc)
end

#generic_form_for(record, *args, &proc) ⇒ Object

generic_form_for @post, :html => => true do |f|

..form content Behaves the same as form form. Adittional options:

autofocus: false - will tur off autofocus for this form
           by default autofocus is on and will set autofocus attribute to first visible element


17
18
19
20
21
22
23
24
# File 'lib/generic_form_for/helpers/form_helper.rb', line 17

def generic_form_for(record, *args, &proc)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options[:builder] ||= GenericFormFor::FormBuilder
  self.builder = options[:builder]
  options[:html] ||= {}
  self.record, self.args, self.proc = record, *(args << options), proc
  instance_exec &builder.form_wrapper_proc
end