Module: ActionView::Helpers::ActiveRecordHelper

Defined in:
lib/gettext_rails/action_view/active_record_helper.rb

Overview

:nodoc:

Defined Under Namespace

Modules: L10n

Instance Method Summary collapse

Instance Method Details

#error_messages_for_with_gettext_rails(*params) ⇒ Object

:nodoc:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/gettext_rails/action_view/active_record_helper.rb', line 86

def error_messages_for_with_gettext_rails(*params) #:nodoc:
  models = params.select{|param| ! param.kind_of? Hash}
  options = params.extract_options!.symbolize_keys

  header_message = (options.has_key?(:header_message) || options.has_key?(:message_title)) ? (options[:header_message] || options[:message_title]) : (:header)
  message = (options.has_key?(:message) || options.has_key?(:message_explanation)) ? (options[:message] || options[:message_explanation]) :  (:body)

  object = options[:object]
  if object
    objects = [object].flatten
  else
    objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
  end
  count  = objects.inject(0) {|sum, object| sum + object.errors.count }

  options[:object_name] ||= params.first
  normalized_model = options[:object_name].to_s.gsub('_', ' ')
  
  #accept nil's as messages to hide message
  options[:header_message] = L10n.error_message(header_message, normalized_model, count)
  options[:message] = L10n.error_message(message, normalized_model, count)

  new_params = models << options
  error_messages_for_without_gettext_rails(*new_params)
end