Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxivak/9a6cb31950a8f4e37949 to your computer and use it in GitHub Desktop.
Save maxivak/9a6cb31950a8f4e37949 to your computer and use it in GitHub Desktop.
simple_form and bootstrap 3 examples

simple_form and bootstrap 3 - Examples

  • Helper for horizontal form
  • Input groups
  • Custom submit button

Helper for horizontal form for bootstrap 3

Helper

app/helpers/forms/forms_helper.rb

module Forms::FormsHelper
  def horizontal_simple_form_for(resource, options = {}, &block)
    options[:html] ||= {}

    # class
    options[:html][:class] ||= []
    if options[:html][:class].is_a? Array
      options[:html][:class] << 'form-horizontal'
    else
      options[:html][:class] << ' form-horizontal'
    end
    options[:html][:role] = 'form'


    options[:wrapper] = :horizontal_form
    options[:wrapper_mappings] = {
      check_boxes: :horizontal_radio_and_checkboxes,
      radio_buttons: :horizontal_radio_and_checkboxes,
      file: :horizontal_file_input,
      boolean: :horizontal_boolean
    }
    simple_form_for(resource, options, &block)
  end
end

Usage

app/views/orders/_form.html.haml

  = horizontal_simple_form_for @order do |f|
    = f.error_notification

    = f.input :textfield1

    = f.button :submit, 'Save', :class=> 'btn-primary'

Input groups for Bootstrap 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment