Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Voloshin Ruslan http://rubyclub.com.ua/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Customize error_messages_for

// description of your code here

 module ActionView::Helpers::ActiveRecordHelper
   def error_messages_for(object_name, options = {})
    options = options.symbolize_keys
    object = instance_variable_get("@#{object_name}")
    if object && !object.errors.empty?
      content_tag("div",
      content_tag(
      options[:header_tag] || "h2",
      "Возникло #{object.errors.count} ошибок при сохранении"
      ) +
      content_tag("p", "Проблеммы возникли для следующих полей:") +
      content_tag("dl", object.errors.full_messages.collect { |msg| content_tag("dt", msg) }),
      "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
      )
    else
      ""
    end
  end
 end
  

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS