Module: ErrorMessagesForHelper

Defined in:
lib/error_messages_for_helper.rb

Constant Summary collapse

@@html_options =
{ :id => 'error_explanation' }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.html_options(options) ⇒ Object



4
5
6
# File 'lib/error_messages_for_helper.rb', line 4

def self.html_options(options)
  @@html_options = options
end

Instance Method Details

#error_messages_for(object_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/error_messages_for_helper.rb', line 8

def error_messages_for(object_name)
  model = instance_variable_get("@#{object_name}")

  if model.present? && model.errors.present?
    errors_list = capture do
       :ul do
        model.errors.each do |attr, message|
          concat( :li, message)
        end
      end
    end

    result =  :h2, t(:header_message, :scope => 'error_messages_for', :default => 'Unable to save data.').html_safe
    result << (:p, t(:error_list, :scope => 'error_messages_for', :default => 'Errors list:').html_safe)
    result << errors_list
    result =  :div, result, @@html_options
  end
end