<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; override</title>
	<atom:link href="http://seanbehan.com/tag/override/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Change database column names for form validations in Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/change-database-column-names-for-form-validations-in-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/change-database-column-names-for-form-validations-in-rails/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 21:39:56 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[validations]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=888</guid>
		<description><![CDATA[When you use validations in Rails, db column names are used as &#8216;keys&#8217; for error messages. This is usually the preferred way to go about it because this maps nicely to the form fields. However, if you use a virtual attribute this may not be the case. For example, I have a &#8216;password_crypted&#8217; field in [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fchange-database-column-names-for-form-validations-in-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Change database column names for form validations in Rails" data-url="http://seanbehan.com/ruby-on-rails/change-database-column-names-for-form-validations-in-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>When you use validations in Rails, db column names are used as &#8216;keys&#8217; for error messages. This is usually the preferred way to go about it because this maps nicely to the form fields. However, if you use a virtual attribute this may not be the case. For example, I have a &#8216;password_crypted&#8217; field in my users table that I don&#8217;t want my user to see if they fail to complete the field. Instead of returning &#8220;Password crypted cannot be blank&#8221; I just want to tell them that a password can&#8217;t be blank. If you provide a custom &#8216;:message&#8217; on the validation this won&#8217;t replace the column name. The solution is to override the &#8220;human_attribute_name&#8221; class method and map specific column names to the string you want to use instead.</p>
<pre class="wp-code-highlight prettyprint">
class User &amp;lt; ActiveRecord::Base
  validates_presence_of :password_crypted
  ATTR_NAMES = {:password_crypted =&gt; &quot;Password&quot;}
  def self.human_attribute_name(attr)
     ATTR_NAMES[attr.to_sym] || super
  end
end
</pre>
<p>I found these resources helpful while I was in search for a solution to this problem. <a href="http://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails"></p>
<p>http://stackoverflow.com/questions/808547/fully-custom-validation-error-message-with-rails</a></p>
<p><a href="http://henrik.nyh.se/2007/12/change-displayed-column-name-in-rails-validation-messages"></p>
<p>http://henrik.nyh.se/2007/12/change-displayed-column-name-in-rails-validation-messages</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/change-database-column-names-for-form-validations-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

