Module | ArkanisDevelopment::SimpleLocalization::LocalizedActiveRecordHelpers::Rails11 |
In: |
lib/features/localized_active_record_helpers.rb
|
Provides a localized version of the error_messages_for helper. This helper just localizes the heading and first paragraph of the error box. The error messages itself are localized by the localized_models and localized_error_messages features.
It also gives you the possibility to define your own way of generating the HTML output by specifying a block:
error_messages_for :record do |objects, header_message, description, error_messages, localized_object_name, count| content_tag(:p, header_message) + content_tag(:ul, error_messages.collect{|msg| content_tag :li, msg}.join("\n")) end
# File lib/features/localized_active_record_helpers.rb, line 120 120: def error_messages_for(object_name, options = {}) 121: options = options.symbolize_keys 122: object = instance_variable_get("@#{object_name}") 123: count = object.errors.count 124: 125: lang = Language[:helpers, :error_messages_for].symbolize_keys 126: localized_object_name = if options[:object_name] 127: options[:object_name] 128: elsif object.class.respond_to?(:localized_model_name) 129: object.class.localized_model_name 130: else 131: object_name.to_s.gsub('_', ' ') 132: end 133: 134: header_message_mask = lang[:heading][count] || lang[:heading]['n'] 135: header_message = format header_message_mask, count, localized_object_name 136: description = lang[:description] 137: error_messages = object.errors.full_messages 138: 139: unless block_given? 140: content_tag('div', 141: content_tag( 142: options[:header_tag] || 'h2', header_message) + 143: content_tag('p', description) + 144: content_tag('ul', error_messages.collect { |msg| content_tag('li', msg) }), 145: 'id' => options[:id] || 'errorExplanation', 'class' => options[:class] || 'errorExplanation' 146: ) 147: else 148: yield object, header_message, description, error_messages, localized_object_name, count 149: end 150: end