Class: Wallaby::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Wallaby::FormBuilder
- Defined in:
- lib/forms/wallaby/form_builder.rb
Overview
Custom form builder to add more helper functions
Instance Method Summary collapse
-
#error_class(field_name) ⇒ String
Return error class if there is error.
-
#error_messages(field_name) ⇒ String
Build up the HTML for displaying error messages.
-
#label(method, text = nil, options = {}, &block) ⇒ Object
Extend label to accept proc type ‘text` argument.
-
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
Extend select to accept proc type ‘choices` argument.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
Try to delegate method to ‘@template`
42 43 44 45 46 47 48 |
# File 'lib/forms/wallaby/form_builder.rb', line 42 def method_missing(method, *args, &block) return super unless @template.respond_to? method # Delegate the method so that we don't come in here the next time # when same method is called self.class.delegate method, to: :@template @template.public_send method, *args, &block end |
Instance Method Details
#error_class(field_name) ⇒ String
Return error class if there is error
7 8 9 |
# File 'lib/forms/wallaby/form_builder.rb', line 7 def error_class(field_name) 'has-error' if object.errors[field_name].present? end |
#error_messages(field_name) ⇒ String
Build up the HTML for displaying error messages
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/forms/wallaby/form_builder.rb', line 14 def (field_name) errors = Array object.errors[field_name] return if errors.blank? content_tag :ul, class: 'errors' do errors.each do || concat content_tag :li, content_tag(:small, raw()) end end end |
#label(method, text = nil, options = {}, &block) ⇒ Object
Extend label to accept proc type ‘text` argument
27 28 29 30 |
# File 'lib/forms/wallaby/form_builder.rb', line 27 def label(method, text = nil, = {}, &block) text = instance_exec(&text) if text.is_a?(Proc) super end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
Extend select to accept proc type ‘choices` argument
34 35 36 37 |
# File 'lib/forms/wallaby/form_builder.rb', line 34 def select(method, choices = nil, = {}, = {}, &block) choices = instance_exec(&choices) if choices.is_a?(Proc) super end |