Class: Miniform::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Miniform::FormBuilder
- Defined in:
- lib/miniform/form_builder.rb
Direct Known Subclasses
Instance Method Summary collapse
- #collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #content_tag(*args, &block) ⇒ Object
- #datetime_select(method, options = {}, html_options = {}) ⇒ Object
- #errors(name) ⇒ Object
- #fields_for(*args, &block) ⇒ Object
- #form_group(*names, &block) ⇒ Object
- #help_block(name) ⇒ Object
- #label(name, *args) ⇒ Object
- #select(name, choices, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/miniform/form_builder.rb', line 34 def collection_select(method, collection, value_method, text_method, = {}, = {}) = () = (, "form-control") Field.new(self, method, ) do super(method, collection, value_method, text_method, , ) end.render end |
#content_tag(*args, &block) ⇒ Object
64 65 66 |
# File 'lib/miniform/form_builder.rb', line 64 def content_tag(*args, &block) @template.content_tag(*args, &block) end |
#datetime_select(method, options = {}, html_options = {}) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/miniform/form_builder.rb', line 43 def datetime_select(method, = {}, = {}) = () = (, "form-control") Field.new(self, method, ) do super(method, , ) end.render end |
#errors(name) ⇒ Object
60 61 62 |
# File 'lib/miniform/form_builder.rb', line 60 def errors(name) object.errors[name].any? && object.errors[name].join(", ") end |
#fields_for(*args, &block) ⇒ Object
68 69 70 71 72 |
# File 'lib/miniform/form_builder.rb', line 68 def fields_for(*args, &block) = args. [:builder] ||= Miniform::FormBuilder super(*args, , &block) end |
#form_group(*names, &block) ⇒ Object
3 4 5 6 7 |
# File 'lib/miniform/form_builder.rb', line 3 def form_group(*names, &block) classes = %w[ form-group ] classes << "has-error" if names.any? { |n| errors(n) } content_tag :div, class: classes, &block end |
#help_block(name) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/miniform/form_builder.rb', line 52 def help_block(name) if errors(name) content_tag(:div, errors(name), class: "help-block") else nil end end |
#label(name, *args) ⇒ Object
9 10 11 12 |
# File 'lib/miniform/form_builder.rb', line 9 def label(name, *args) = (args., "control-label") super(name, *args, ) end |