Class: FormBootstrap::Builder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/form-bootstrap/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(object_name, object, template, options, proc) ⇒ Builder

Returns a new instance of Builder.



5
6
7
8
# File 'lib/form-bootstrap/builder.rb', line 5

def initialize(object_name, object, template, options, proc)
  super
  @help_css = (options[:help].try(:to_sym) == :block) ? 'help-block' : 'help-inline'
end

Instance Method Details

#actions(&block) ⇒ Object



40
41
42
43
44
# File 'lib/form-bootstrap/builder.rb', line 40

def actions(&block)
   :div, class: "actions" do
    block.call
  end
end

#alert_message(title, *args) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/form-bootstrap/builder.rb', line 50

def alert_message(title, *args)
  options = args.extract_options!
  css = options[:class] || "alert-message error"

  if object.errors.full_messages.any?
     :div, class: css do
      title
    end
  end
end

#check_box(name, *args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/form-bootstrap/builder.rb', line 25

def check_box(name, *args)
  options = args.extract_options!.symbolize_keys!
   :div, class: "clearfix#{(' error' if object.errors[name].any?)}"  do
    (:div, class: 'input') do
      (:ul, class: 'inputs-list') do
        (:li) do
          args << options.except(:label, :help)
          html = super(name, *args) + ' ' + (:span) { options[:label] }
          label(name, html)
        end
      end
    end
  end
end

#primary(name) ⇒ Object



46
47
48
# File 'lib/form-bootstrap/builder.rb', line 46

def primary(name)
  submit name, class: 'btn primary'
end