Class: RPH::FormAssistant::FieldErrors

Inherits:
Array
  • Object
show all
Defined in:
lib/form_assistant/field_errors.rb

Overview

extensions for formatting error messages

Ex: <%= errors %>
    <%= errors.to_s(:break => true) %>
    <%= errors.to_list %>
    <%= errors.to_list(:class => 'errorz') %>

Instance Method Summary collapse

Instance Method Details

#to_list(options = {}) ⇒ Object

converts an array into an unordered list



16
17
18
19
20
21
22
23
24
# File 'lib/form_assistant/field_errors.rb', line 16

def to_list(options = {})
  css_class = options.delete(:class) || 'errors'
    
  list_items = self.inject("") do |items, error|
    items << "<li>#{error}</li>"
  end
    
  return '<ul class="%s">%s</ul>' % [css_class, list_items]
end

#to_s(options = {}) ⇒ Object



10
11
12
13
# File 'lib/form_assistant/field_errors.rb', line 10

def to_s(options = {})
  return self.join('<br />') if options[:break]
  self.to_sentence
end