Module: SimpleForm::ActionViewExtensions::Builder

Included in:
ActionView::Helpers::FormBuilder
Defined in:
lib/simple_form/action_view_extensions/builder.rb

Overview

A collection of methods required by simple_form but added to rails default form. This means that you can use such methods outside simple_form context.

Instance Method Summary (collapse)

Instance Method Details

- (Object) simple_fields_for(*args, &block)

Wrapper for using SimpleForm inside a default rails form. Example:

form_for @user do |f|
  f.simple_fields_for :posts do |posts_form|
    # Here you have all simple_form methods available
    posts_form.input :title
  end
end


16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/simple_form/action_view_extensions/builder.rb', line 16

def simple_fields_for(*args, &block)
  options = args.extract_options!
  options[:wrapper] = self.options[:wrapper] if options[:wrapper].nil?
  options[:defaults] ||= self.options[:defaults]

  if self.class < ActionView::Helpers::FormBuilder
    options[:builder] ||= self.class
  else
    options[:builder] ||= SimpleForm::FormBuilder
  end
  fields_for(*args, options, &block)
end