Module: Motr::Forms::Helpers

Defined in:
lib/motr/forms/helpers.rb

Overview

# Custom form helpers and modifications

Instance Method Summary collapse

Instance Method Details

#motr_form(record_name_or_array, *args, &proc) ⇒ Object

Cusomizes the default form_for helper to add additional functionality All params are the same as Rails’ form_for

Parameters:

  • record_name_or_array (Mixed)
  • args (Array)
  • &block (Block)

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/motr/forms/helpers.rb', line 18

def motr_form(record_name_or_array, *args, &proc)
 
  raise ArgumentError, "Missing block" unless block_given?
  
  options = args.extract_options!
  options.reverse_merge!(:builder => Motr::Forms.default_builder)
  options[:html] ||= {}
  options[:html].merge!('data-validatable' => true) if options.delete(:validate)
  
  Motr::Forms.with_custom_error_proc do
    form_for(record_name_or_array, *(args << options), &proc)
  end
  
end