Class: BootstrapFormBuilder::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- BootstrapFormBuilder::FormBuilder
- Defined in:
- lib/bootstrap_form_builder/form_builder.rb
Instance Method Summary collapse
- #collection_select(attribute, collection, value_method, text_method, options = {}) ⇒ Object
- #field(input_tag, attribute, options) ⇒ Object
- #file_field(attribute, options = {}, &block) ⇒ Object
- #password_field(attribute, options = {}, &block) ⇒ Object
- #submit(value = nil, options = {}) ⇒ Object
- #text_field(attribute, options = {}, &block) ⇒ Object
- #uneditable_field(attribute, options = {}) ⇒ Object
Instance Method Details
#collection_select(attribute, collection, value_method, text_method, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/bootstrap_form_builder/form_builder.rb', line 18 def collection_select(attribute, collection, value_method, text_method, = {}) select_tag = super field(select_tag, attribute, ) end |
#field(input_tag, attribute, options) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bootstrap_form_builder/form_builder.rb', line 42 def field(input_tag, attribute, ) errors = object.errors[attribute].uniq.to_sentence outer_class = errors.blank? ? 'clearfix' : 'clearfix error' inner_class = errors.blank? ? 'input' : 'input error' template.content_tag(:div, id: "#{object.class.model_name.underscore}_#{attribute}_input", class: outer_class) do label(attribute, [:label]) << template.content_tag(:div, class: inner_class) do input_div = input_tag input_div << template.content_tag(:span, [:hint], class: 'help-block') if [:hint] input_div << template.content_tag(:span, errors, class: 'help-inline') if errors.present? input_div end end end |
#file_field(attribute, options = {}, &block) ⇒ Object
13 14 15 16 |
# File 'lib/bootstrap_form_builder/form_builder.rb', line 13 def file_field(attribute, = {}, &block) input_tag = block_given? ? template.capture(super, &block) : super field(input_tag, attribute, ) end |
#password_field(attribute, options = {}, &block) ⇒ Object
8 9 10 11 |
# File 'lib/bootstrap_form_builder/form_builder.rb', line 8 def password_field(attribute, = {}, &block) input_tag = block_given? ? template.capture(super, &block) : super field(input_tag, attribute, ) end |
#submit(value = nil, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bootstrap_form_builder/form_builder.rb', line 28 def submit(value = nil, = {}) # This version of #submit differs slightly from the ActionView version in that # the model name is titleized to maintain consistent capitalization, e.g., for # a model named QuoteRequest the button label is "Create Quote Request" rather # than "Create Quote request". value ||= "#{object.new_record? ? 'Create' : 'Update'} #{object.class.model_name.titleize}" = ['btn', *.delete(:class)].join(' ') template.content_tag :div, class: 'clearfix' do template.content_tag :div, class: 'actions' do super(value, .merge(class: )) end end end |
#text_field(attribute, options = {}, &block) ⇒ Object
3 4 5 6 |
# File 'lib/bootstrap_form_builder/form_builder.rb', line 3 def text_field(attribute, = {}, &block) input_tag = block_given? ? template.capture(super, &block) : super field(input_tag, attribute, ) end |
#uneditable_field(attribute, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/bootstrap_form_builder/form_builder.rb', line 23 def uneditable_field(attribute, = {}) span_tag = template.content_tag(:span, object.send(attribute), class: 'uneditable-input', id: "#{object.class.model_name.underscore}_#{attribute}") field(span_tag, attribute, ) end |