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)
Delegate missing method to ‘@template`
46 47 48 49 50 51 52 53 |
# File 'lib/forms/wallaby/form_builder.rb', line 46 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.try method, *args, &block end |
Instance Method Details
#error_class(field_name) ⇒ String
Return error class if there is error
9 10 11 |
# File 'lib/forms/wallaby/form_builder.rb', line 9 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
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/forms/wallaby/form_builder.rb', line 16 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
31 32 33 34 |
# File 'lib/forms/wallaby/form_builder.rb', line 31 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
38 39 40 41 |
# File 'lib/forms/wallaby/form_builder.rb', line 38 def select(method, choices = nil, = {}, = {}, &block) choices = instance_exec(&choices) if choices.is_a?(Proc) super end |