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`
40 41 42 43 44 45 46 |
# File 'lib/forms/wallaby/form_builder.rb', line 40 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 # 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
26 27 28 29 |
# File 'lib/forms/wallaby/form_builder.rb', line 26 def label(method, text = nil, = {}, &block) text = instance_exec(&text) if text.respond_to? :call super end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
Extend select to accept proc type ‘choices` argument
32 33 34 35 |
# File 'lib/forms/wallaby/form_builder.rb', line 32 def select(method, choices = nil, = {}, = {}, &block) choices = instance_exec(&choices) if choices.respond_to? :call super end |