<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: error_messages_for code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 12 Oct 2008 16:07:16 GMT</pubDate>
    <description>DZone Snippets: error_messages_for code</description>
    <item>
      <title>Customize error_messages_for</title>
      <link>http://snippets.dzone.com/posts/show/4710</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; module ActionView::Helpers::ActiveRecordHelper&lt;br /&gt;   def error_messages_for(object_name, options = {})&lt;br /&gt;    options = options.symbolize_keys&lt;br /&gt;    object = instance_variable_get("@#{object_name}")&lt;br /&gt;    if object &amp;&amp; !object.errors.empty?&lt;br /&gt;      content_tag("div",&lt;br /&gt;      content_tag(&lt;br /&gt;      options[:header_tag] || "h2",&lt;br /&gt;      "&#1042;&#1086;&#1079;&#1085;&#1080;&#1082;&#1083;&#1086; #{object.errors.count} &#1086;&#1096;&#1080;&#1073;&#1086;&#1082; &#1087;&#1088;&#1080; &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1077;&#1085;&#1080;&#1080;"&lt;br /&gt;      ) +&lt;br /&gt;      content_tag("p", "&#1055;&#1088;&#1086;&#1073;&#1083;&#1077;&#1084;&#1084;&#1099; &#1074;&#1086;&#1079;&#1085;&#1080;&#1082;&#1083;&#1080; &#1076;&#1083;&#1103; &#1089;&#1083;&#1077;&#1076;&#1091;&#1102;&#1097;&#1080;&#1093; &#1087;&#1086;&#1083;&#1077;&#1081;:") +&lt;br /&gt;      content_tag("dl", object.errors.full_messages.collect { |msg| content_tag("dt", msg) }),&lt;br /&gt;      "id" =&gt; options[:id] || "errorExplanation", "class" =&gt; options[:class] || "errorExplanation"&lt;br /&gt;      )&lt;br /&gt;    else&lt;br /&gt;      ""&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt; end&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 29 Oct 2007 08:45:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4710</guid>
      <author>bublik (Voloshin Ruslan)</author>
    </item>
  </channel>
</rss>
