class Wallaby::FormBuilder
Custom
form builder to add more helper functions
Public Instance Methods
error_class(field_name)
click to toggle source
Return error class if there is error @param field_name [String/Symbol] @return [String]
# 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)
click to toggle source
Build up the HTML for displaying error messages @param field_name [String/Symbol] @return [String] HTML
# File lib/forms/wallaby/form_builder.rb, line 16 def error_messages(field_name) errors = Array object.errors[field_name] return if errors.blank? content_tag :ul, class: 'errors' do errors.each do |message| concat content_tag :li, content_tag( :small, raw(message) # rubocop:disable Rails/OutputSafety ) end end end
label(method, text = nil, options = {}, &block)
click to toggle source
Extend label to accept proc type `text` argument @see ActionView::Helpers::FormBuilder#label
Calls superclass method
# File lib/forms/wallaby/form_builder.rb, line 31 def label(method, text = nil, options = {}, &block) text = instance_exec(&text) if text.is_a?(Proc) super end
select(method, choices = nil, options = {}, html_options = {}, &block)
click to toggle source
Extend select to accept proc type `choices` argument @see ActionView::Helpers::FormBuilder#select
Calls superclass method
# File lib/forms/wallaby/form_builder.rb, line 38 def select(method, choices = nil, options = {}, html_options = {}, &block) choices = instance_exec(&choices) if choices.is_a?(Proc) super end
Protected Instance Methods
method_missing(method, *args, &block)
click to toggle source
Delegate missing method to `@template`
Calls superclass method
# 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.public_send method, *args, &block end
respond_to_missing?(method, _include_private)
click to toggle source
Delegate missing method check to `@template`
Calls superclass method
# File lib/forms/wallaby/form_builder.rb, line 56 def respond_to_missing?(method, _include_private) @template.respond_to?(method) || super end