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

Customize error_messages_for (See related posts)

// 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
  


You need to create an account or log in to post comments to this site.


Click here to browse all 4856 code snippets

Related Posts