Class: FormGroupHelper::FormGroupBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/form_group_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, attribute, form) ⇒ FormGroupBuilder

Returns a new instance of FormGroupBuilder.



3
4
5
6
7
# File 'app/helpers/form_group_helper.rb', line 3

def initialize(template, attribute, form)
  @template = template
  @attribute = attribute
  @form = form
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'app/helpers/form_group_helper.rb', line 22

def method_missing(name, *args, &block)
  if @form.respond_to?(name)
    @form.__send__(name, *args, &block)
  else
    super
  end
end

Instance Method Details

#error_messagesObject

Error message specific to one attribute to be shown inside a control group.



14
15
16
17
18
19
20
# File 'app/helpers/form_group_helper.rb', line 14

def error_messages
  if has_errors?
    @template. :span,
      @template.fa_icon_tag("remove") + " " + @form.object.errors[@attribute].to_sentence,
      :class => "help-block"
  end
end

#has_errors?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/helpers/form_group_helper.rb', line 9

def has_errors?
  @form.object.respond_to?(:errors) && @form.object.errors[@attribute].any?
end