Class: BootstrapFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- BootstrapFormBuilder
- Defined in:
- app/form_builders/bootstrap_form_builder.rb
Instance Method Summary collapse
- #check_box(name) ⇒ Object
- #errors_for ⇒ Object
- #select(name, choices, options = {}) ⇒ Object
- #submit(value = nil) ⇒ Object
- #wrapper(name, options = {}, &block) ⇒ Object
Instance Method Details
#check_box(name) ⇒ Object
48 49 50 51 52 53 54 |
# File 'app/form_builders/bootstrap_form_builder.rb', line 48 def check_box(name) wrapper name do content_tag :label, class: 'checkbox' do super(name) end end end |
#errors_for ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/form_builders/bootstrap_form_builder.rb', line 4 def errors_for return "" if @object.errors.empty? = @object.errors..map { |msg| content_tag(:li, msg) }.join sentence = I18n.t( "errors.template.header", :count => @object.errors.count, :model => @object.class.model_name.human ) html = <<-HTML <div class="alert alert-error"> <p><b>#{sentence}</b></p> <ul>#{}</ul> </div> HTML html.html_safe end |
#select(name, choices, options = {}) ⇒ Object
42 43 44 45 46 |
# File 'app/form_builders/bootstrap_form_builder.rb', line 42 def select(name, choices, = {}) wrapper name do super end end |
#submit(value = nil) ⇒ Object
56 57 58 59 60 |
# File 'app/form_builders/bootstrap_form_builder.rb', line 56 def submit(value=nil) content_tag :div, class: 'form-actions' do super value, class: 'btn btn-primary' end end |
#wrapper(name, options = {}, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/form_builders/bootstrap_form_builder.rb', line 62 def wrapper(name, = {}, &block) content_tag :div, class: ['control-group', ('error' if @object.errors[name].present?)] do safe_join [ label(name, class: 'control-label'), content_tag(:div, class: 'controls'){ safe_join [ yield, (content_tag(:p, [:hint], class: 'help-block') if [:hint].present?) ] } ] end end |