class Miniform::FormBuilder

Public Instance Methods

collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) click to toggle source
Calls superclass method
# File lib/miniform/form_builder.rb, line 34
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
  field_options = extract_field_options!(options)
  html_options = options_with_class(html_options, "form-control")

  Field.new(self, method, field_options) do
    super(method, collection, value_method, text_method, options, html_options)
  end.render
end
content_tag(*args, &block) click to toggle source
# File lib/miniform/form_builder.rb, line 64
def content_tag(*args, &block)
  @template.content_tag(*args, &block)
end
datetime_select(method, options = {}, html_options = {}) click to toggle source
Calls superclass method
# File lib/miniform/form_builder.rb, line 43
def datetime_select(method, options = {}, html_options = {})
  field_options = extract_field_options!(options)
  html_options = options_with_class(html_options, "form-control")

  Field.new(self, method, field_options) do
    super(method, options, html_options)
  end.render
end
errors(name) click to toggle source
# File lib/miniform/form_builder.rb, line 60
def errors(name)
  object.errors[name].any? && object.errors[name].join(", ")
end
fields_for(*args, &block) click to toggle source
Calls superclass method
# File lib/miniform/form_builder.rb, line 68
def fields_for(*args, &block)
  options = args.extract_options!
  options[:builder] ||= Miniform::FormBuilder
  super(*args, options, &block)
end
form_group(*names, &block) click to toggle source
# File lib/miniform/form_builder.rb, line 3
def form_group(*names, &block)
  classes = %w[ form-group ]
  classes << "has-error" if names.any? { |n| errors(n) }
  content_tag :div, class: classes, &block
end
help_block(name) click to toggle source
# File lib/miniform/form_builder.rb, line 52
def help_block(name)
  if errors(name)
    content_tag(:div, errors(name), class: "help-block")
  else
    nil
  end
end
label(name, *args) click to toggle source
Calls superclass method
# File lib/miniform/form_builder.rb, line 9
def label(name, *args)
  options = options_with_class(args.extract_options!, "control-label")
  super(name, *args, options)
end
select(name, choices, options = {}, html_options = {}) click to toggle source
Calls superclass method
# File lib/miniform/form_builder.rb, line 25
def select(name, choices, options = {}, html_options = {})
  field_options = extract_field_options!(options)
  html_options = options_with_class(html_options, "form-control")

  Field.new(self, name, field_options) do
    super(name, choices, options, html_options)
  end.render
end

Private Instance Methods

extract_field_options!(options) click to toggle source
# File lib/miniform/form_builder.rb, line 76
def extract_field_options!(options)
  options.extract!(:label, :error)
end
options_with_class(options, css_class) click to toggle source
# File lib/miniform/form_builder.rb, line 80
def options_with_class(options, css_class)
  options.dup.tap do |o|
    o[:class] = Array(o[:class]) << css_class
  end
end