<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Class: ActiveRecord::Error</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" /> <script type="text/javascript"> // <![CDATA[ function popupCode( url ) { window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400") } function toggleCode( id ) { if ( document.getElementById ) elem = document.getElementById( id ); else if ( document.all ) elem = eval( "document.all." + id ); else return false; elemStyle = elem.style; if ( elemStyle.display != "block" ) { elemStyle.display = "block" } else { elemStyle.display = "none" } return true; } // Make codeblocks hidden by default document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" ) // ]]> </script> </head> <body> <div id="classHeader"> <table class="header-table"> <tr class="top-aligned-row"> <td><strong>Class</strong></td> <td class="class-name-in-header">ActiveRecord::Error</td> </tr> <tr class="top-aligned-row"> <td><strong>In:</strong></td> <td> <a href="../../files/lib/active_record/validations_rb.html"> lib/active_record/validations.rb </a> <br /> </td> </tr> <tr class="top-aligned-row"> <td><strong>Parent:</strong></td> <td> Object </td> </tr> </table> </div> <!-- banner header --> <div id="bodyContent"> <div id="contextContent"> </div> <div id="method-list"> <h3 class="section-bar">Methods</h3> <div class="name-list"> <a href="#M000576">full_message</a> <a href="#M000580">generate_full_message</a> <a href="#M000579">generate_message</a> <a href="#M000575">message</a> <a href="#M000574">new</a> <a href="#M000577">to_s</a> <a href="#M000578">value</a> </div> </div> </div> <!-- if includes --> <div id="section"> <div id="attribute-list"> <h3 class="section-bar">Attributes</h3> <div class="name-list"> <table> <tr class="top-aligned-row context-row"> <td class="context-item-name">attribute</td> <td class="context-item-value"> [RW] </td> <td class="context-item-desc"></td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">base</td> <td class="context-item-value"> [RW] </td> <td class="context-item-desc"></td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">message</td> <td class="context-item-value"> [RW] </td> <td class="context-item-desc"></td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">options</td> <td class="context-item-value"> [RW] </td> <td class="context-item-desc"></td> </tr> <tr class="top-aligned-row context-row"> <td class="context-item-name">type</td> <td class="context-item-value"> [RW] </td> <td class="context-item-desc"></td> </tr> </table> </div> </div> <!-- if method_list --> <div id="methods"> <h3 class="section-bar">Public Class methods</h3> <div id="method-M000574" class="method-detail"> <a name="M000574"></a> <div class="method-heading"> <a href="Error.src/M000574.html" target="Code" class="method-signature" onclick="popupCode('Error.src/M000574.html');return false;"> <span class="method-name">new</span><span class="method-args">(base, attribute, type = nil, options = {})</span> </a> </div> <div class="method-description"> </div> </div> <h3 class="section-bar">Public Instance methods</h3> <div id="method-M000576" class="method-detail"> <a name="M000576"></a> <div class="method-heading"> <a href="Error.src/M000576.html" target="Code" class="method-signature" onclick="popupCode('Error.src/M000576.html');return false;"> <span class="method-name">full_message</span><span class="method-args">()</span> </a> </div> <div class="method-description"> </div> </div> <div id="method-M000575" class="method-detail"> <a name="M000575"></a> <div class="method-heading"> <a href="Error.src/M000575.html" target="Code" class="method-signature" onclick="popupCode('Error.src/M000575.html');return false;"> <span class="method-name">message</span><span class="method-args">()</span> </a> </div> <div class="method-description"> </div> </div> <div id="method-M000577" class="method-detail"> <a name="M000577"></a> <div class="method-heading"> <span class="method-name">to_s</span><span class="method-args">()</span> </div> <div class="method-description"> <p> Alias for <a href="Error.html#M000575">message</a> </p> </div> </div> <div id="method-M000578" class="method-detail"> <a name="M000578"></a> <div class="method-heading"> <a href="Error.src/M000578.html" target="Code" class="method-signature" onclick="popupCode('Error.src/M000578.html');return false;"> <span class="method-name">value</span><span class="method-args">()</span> </a> </div> <div class="method-description"> </div> </div> <h3 class="section-bar">Protected Instance methods</h3> <div id="method-M000580" class="method-detail"> <a name="M000580"></a> <div class="method-heading"> <a href="Error.src/M000580.html" target="Code" class="method-signature" onclick="popupCode('Error.src/M000580.html');return false;"> <span class="method-name">generate_full_message</span><span class="method-args">(message, options = {})</span> </a> </div> <div class="method-description"> <p> Wraps an error <a href="Error.html#M000575">message</a> into a <a href="Error.html#M000576">full_message</a> format. </p> <p> The default <a href="Error.html#M000576">full_message</a> format for any locale is <tt>"{{attribute}} {{<a href="Error.html#M000575">message</a>}}"</tt>. One can specify locale specific default <a href="Error.html#M000576">full_message</a> format by storing it as a translation for the key <tt>:"activerecord.errors.full_messages.format"</tt>. </p> <p> Additionally one can specify a validation specific error <a href="Error.html#M000575">message</a> format by storing a translation for <tt>:"activerecord.errors.full_messages.[message_key]"</tt>. E.g. the <a href="Error.html#M000576">full_message</a> format for any validation that uses :blank as a <a href="Error.html#M000575">message</a> key (such as validates_presence_of) can be stored to <tt>:"activerecord.errors.full_messages.blank".</tt> </p> <p> Because the <a href="Error.html#M000575">message</a> key used by a validation can be overwritten on the <tt>validates_*</tt> class macro level one can customize the <a href="Error.html#M000576">full_message</a> format for any particular validation: </p> <pre> # app/models/article.rb class Article < ActiveRecord::Base validates_presence_of :title, :message => :"title.blank" end # config/locales/en.yml en: activerecord: errors: full_messages: title: blank: This title is screwed! </pre> </div> </div> <div id="method-M000579" class="method-detail"> <a name="M000579"></a> <div class="method-heading"> <a href="Error.src/M000579.html" target="Code" class="method-signature" onclick="popupCode('Error.src/M000579.html');return false;"> <span class="method-name">generate_message</span><span class="method-args">(message, options = {})</span> </a> </div> <div class="method-description"> <p> Translates an error <a href="Error.html#M000575">message</a> in it‘s default scope (<tt>activerecord.errrors.messages</tt>). <a href="Error.html">Error</a> messages are first looked up in <tt>models.MODEL.attributes.ATTRIBUTE.MESSAGE</tt>, if it‘s not there, it‘s looked up in <tt>models.MODEL.MESSAGE</tt> and if that is not there it returns the translation of the default <a href="Error.html#M000575">message</a> (e.g. <tt>activerecord.errors.messages.MESSAGE</tt>). The translated model name, translated attribute name and the <a href="Error.html#M000578">value</a> are available for interpolation. </p> <p> When using inheritence in your models, it will check all the inherited models too, but only if the model itself hasn‘t been found. Say you have <tt>class Admin < User; end</tt> and you wanted the translation for the <tt>:blank</tt> error <tt><a href="Error.html#M000575">message</a></tt> for the <tt>title</tt> <tt>attribute</tt>, it looks for these translations: </p> <p> <ol> <li><tt>activerecord.errors.models.admin.attributes.title.blank</tt></li> <li><tt>activerecord.errors.models.admin.blank</tt></li> <li><tt>activerecord.errors.models.user.attributes.title.blank</tt></li> <li><tt>activerecord.errors.models.user.blank</tt></li> <li><tt>activerecord.errors.messages.blank</tt></li> <li>any default you provided through the <tt>options</tt> hash (in the activerecord.errors scope)</li> </ol> </p> </div> </div> </div> </div> <div id="validator-badges"> <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p> </div> </body> </html>