Module: TwiceBaked::ApplicationHelper

Defined in:
app/helpers/twice_baked/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#tb_form_error_field(record, attribute) ⇒ Object



26
27
28
29
30
31
# File 'app/helpers/twice_baked/application_helper.rb', line 26

def tb_form_error_field(record, attribute)
  message = record.errors[attribute].first
  if message
    return  :p, message, :class => 'help-block form-field-error'
  end
end

#tb_form_error_header(record) ⇒ Object



19
20
21
22
23
24
# File 'app/helpers/twice_baked/application_helper.rb', line 19

def tb_form_error_header(record)
  if record.errors.any?
    message = "Please correct the following #{'error'.pluralize(record.errors.size)}:"
    return  :h4, message, :class => 'form-field-error'
  end
end

#tb_form_errors(record, *fields_to_display) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/twice_baked/application_helper.rb', line 3

def tb_form_errors(record, *fields_to_display)
  if record.errors.any?
     :div, :class => 'form-errors' do
      concat(tb_form_error_header(record))
      concat(raw "<ul>")
      if fields_to_display.any?
        messages = fields_to_display.collect{ |field| record.errors.full_messages_for(field) }.flatten()
      else
        messages = record.errors.full_messages
      end
      concat(raw messages.collect{ |msg| "<li>#{msg}</li>" }.join())
      concat(raw "</ul>")
    end
  end
end

#tb_form_field(attribute) ⇒ Object



33
34
35
36
37
38
39
40
# File 'app/helpers/twice_baked/application_helper.rb', line 33

def tb_form_field(attribute)
   :div, :class => 'form-group' do
    concat label_tag attribute, attribute, :class => 'col-sm-2 control-label'
    concat((:div, :class => 'col-sm-10') do
      text_field_tag attribute, :placeholder => attribute, :class => 'form-control'
    end)
  end
end