Class: TwitterBootstrap::Helpers::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- TwitterBootstrap::Helpers::FormBuilder
- Defined in:
- lib/twitter_bootstrap-helpers/form_builder.rb
Instance Method Summary collapse
- #control_group(attr, text = nil, &block) ⇒ Object
- #controls(attr, &block) ⇒ Object
- #errors_on(attr) ⇒ Object
-
#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>.
- #submit(value = nil, options = {}) ⇒ Object
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 ) = { class: 'control-group' } [:class] += ' error' if @object.errors[attr].any? @template.content_tag :div, 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.content_tag :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.content_tag(: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, ={}) [:class] = 'btn btn-primary' unless .has_key? :class super value, end |