Class: TwitterBootstrap::Helpers::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
lib/twitter_bootstrap-helpers/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#control_group(attr, text = nil, &block) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/twitter_bootstrap-helpers/form_builder.rb', line 44

def control_group(attr, text = nil, &block )
  options = { class: 'control-group' }
  options[:class] += ' error' if @object.errors[attr].any?
  @template. :div, options do
    @template.concat label(attr, text, class: 'control-label')
    @template.concat controls(attr){yield}
  end
end

#controls(attr, &block) ⇒ Object



53
54
55
56
57
58
# File 'lib/twitter_bootstrap-helpers/form_builder.rb', line 53

def controls(attr, &block)
  @template. :div, class: 'controls' do
    yield
    @template.concat errors_on(attr)
  end
end

#errors_on(attr) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/twitter_bootstrap-helpers/form_builder.rb', line 60

def errors_on(attr)
  if @object.errors[attr].any?
    @template.(:span,
      @object.errors[attr].to_sentence,
      class: 'help-inline'
    )
  end
end

#field_control_group(type, attr, *args) ⇒ Object

Control Group Example <div class=“control-group”>

<label class="control-label" for="input_id">Text Input</label>
<div class="controls">
  <input type="input_type" class="input-xlarge" id="input_id" />
</div>

</div>



38
39
40
41
42
# File 'lib/twitter_bootstrap-helpers/form_builder.rb', line 38

def field_control_group(type, attr, *args)
  control_group attr do
    @template.concat send(type, attr, *args)
  end
end

#submit(value = nil, options = {}) ⇒ Object



25
26
27
28
# File 'lib/twitter_bootstrap-helpers/form_builder.rb', line 25

def submit(value=nil, options={})
  options[:class] = 'btn btn-primary' unless options.has_key? :class
  super value, options
end