class Formtastic::FormBuilder

Attributes

auto_index[R]
template[R]

Public Class Methods

configure(name, default = nil) click to toggle source

Defines a new configurable option @param [Symbol] name the configuration name @param [Object] default the configuration default value @private

@!macro [new] configure

@!scope class
@!attribute [rw] $1
@api public
# File lib/formtastic/form_builder.rb, line 13
def self.configure(name, default = nil)
  class_attribute(name)
  self.send(:"#{name}=", default)
end
new(object_name, object, template, options, block=nil) click to toggle source
Calls superclass method
# File lib/formtastic/form_builder.rb, line 103
def initialize(object_name, object, template, options, block=nil)
  # rails 3 supported passing in the block parameter to FormBuilder
  # rails 4.0 deprecated the block parameter and does nothing with it
  # rails 4.1 removes the parameter completely
  if Util.rails3? || Util.rails4_0?
    super
  else # Must be rails4_1 or greater
    super object_name, object, template, options
  end

  if respond_to?('multipart=') && options.is_a?(Hash) && options[:html]
    self.multipart = options[:html][:multipart]
  end
end

Public Instance Methods

semantic_fields_for(record_or_name_or_array, *args, &block) click to toggle source

This is a wrapper around Rails' `ActionView::Helpers::FormBuilder#fields_for`, originally provided to ensure that the `:builder` from `semantic_form_for` was passed down into the nested `fields_for`. Rails 3 no longer requires us to do this, so this method is provided purely for backwards compatibility and DSL consistency.

When constructing a `fields_for` form fragment outside of `semantic_form_for`, please use `Formtastic::Helpers::FormHelper#semantic_fields_for`.

@see api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-fields_for ActionView::Helpers::FormBuilder#fields_for @see api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for ActionView::Helpers::FormHelper#fields_for @see Formtastic::Helpers::FormHelper#semantic_fields_for

@example

<% semantic_form_for @post do |post| %>
  <% post.semantic_fields_for :author do |author| %>
    <% author.inputs :name %>
  <% end %>
<% end %>

<form ...>
  <fieldset class="inputs">
    <ol>
      <li class="string"><input type='text' name='post[author][name]' id='post_author_name' /></li>
    </ol>
  </fieldset>
</form>

@todo is there a way to test the params structure of the Rails helper we wrap to ensure forward compatibility?

# File lib/formtastic/form_builder.rb, line 94
def semantic_fields_for(record_or_name_or_array, *args, &block)
  # Add a :parent_builder to the args so that nested translations can be possible in Rails 3
  options = args.extract_options!
  options[:parent_builder] ||= self

  # Wrap the Rails helper
  fields_for(record_or_name_or_array, *(args << options), &block)
end