<?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>Ryan Coughlin &#124; Web and Graphic Designer &#187; validation</title>
	<atom:link href="http://www.ryancoughlin.com/tag/validation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ryancoughlin.com</link>
	<description></description>
	<lastBuildDate>Fri, 26 Mar 2010 00:07:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Validating with Rails</title>
		<link>http://www.ryancoughlin.com/2008/11/04/validating-with-rails/</link>
		<comments>http://www.ryancoughlin.com/2008/11/04/validating-with-rails/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 19:38:18 +0000</pubDate>
		<dc:creator>Ryan Coughlin</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.ryancoughlin.com/?p=107</guid>
		<description><![CDATA[Ruby on Rails is one of the more popular MVC frameworks out there along with .NET, Zend, and CakePHP. Every day more and more resources are being published regarding Ruby on Rails. One of the nice things about Ruby on Rails is that it makes easy to help validate forms within your rails application. If [...]


Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/03/cracking-down-with-ruby-on-rails/' rel='bookmark' title='Permanent Link: Cracking down with Ruby on Rails'>Cracking down with Ruby on Rails</a> <small>So over the weekend I finally sat back down and...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/10/installing-ruby-on-rails-plugins-via-mediatemple/' rel='bookmark' title='Permanent Link: Installing Ruby on Rails Plugins via MediaTemple'>Installing Ruby on Rails Plugins via MediaTemple</a> <small>Good Morning and Happy Mothers Day! I have been running...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/active-record-already-activated/' rel='bookmark' title='Permanent Link: Active Record Already Activated'>Active Record Already Activated</a> <small>After spending hours and hours staring at line after line...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Ruby on Rails is one of the more popular MVC frameworks out there along with .NET, Zend, and CakePHP. Every day more and more resources are being published regarding Ruby on Rails. One of the nice things about Ruby on Rails is that it makes easy to help validate forms within your rails application. If you want to check for the presence of text for a field it would be something like:</p>
<pre class="ruby" name="code">validates_presence_of :comment</pre>
<p>That checks for the field name comment, like in the code snippet below. This will produce the input tag using rails.</p>
<pre class="ruby" name="code">&lt;%= text_field "comment", "comment" %&gt;</pre>
<p>The other section to make it all run is the</p>
<pre class="ruby" name="code">&lt;%= error_messages_for 'model_name' %&gt;</pre>
<p>Place this line of code at the top of your form, and replace &#8220;model_name&#8221; with the model name your application refers too.  It tells the application to look at the validation rules you set up. Once you have those in place, you should not be able to submit the form with a blank input.</p>
<p>A few other predefined rules built in to Ruby on Rails are:</p>
<p><strong>Field should not be empty</strong></p>
<p><em>Code: validates_presence_of<br />
Example: validates_presence_of :user_name, :password </em></p>
<p><strong>Field should Numerical</strong></p>
<p><em>Code</em><em>: validates_numericality_of<br />
Example: validates_numericality_of :value </em></p>
<p><strong>Field should not be Unique</strong></p>
<p><em>Code</em><em>:validates_uniqueness_of<br />
Example: validates_uniqueness_of :user_name </em></p>
<p><strong>Field Need to be of size X</strong></p>
<p><em>Code</em><em>: validates_length_of<br />
Example: validates_length_of :state_code, :is=&gt;2 </em></p>
<p><strong>Field size Need to be of between X to Y</strong></p>
<p><em>Code</em><em>: validates_length_of<br />
Example: validates_uniqueness_of :user_name</em></p>
<p>To learn more about validation and to read up on the rest of the Rails API, read <a href="http://api.rubyonrails.org/" target="_blank">this</a></p>


<p>Related posts:<ol><li><a href='http://www.ryancoughlin.com/2008/11/03/cracking-down-with-ruby-on-rails/' rel='bookmark' title='Permanent Link: Cracking down with Ruby on Rails'>Cracking down with Ruby on Rails</a> <small>So over the weekend I finally sat back down and...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/10/installing-ruby-on-rails-plugins-via-mediatemple/' rel='bookmark' title='Permanent Link: Installing Ruby on Rails Plugins via MediaTemple'>Installing Ruby on Rails Plugins via MediaTemple</a> <small>Good Morning and Happy Mothers Day! I have been running...</small></li>
<li><a href='http://www.ryancoughlin.com/2009/05/04/active-record-already-activated/' rel='bookmark' title='Permanent Link: Active Record Already Activated'>Active Record Already Activated</a> <small>After spending hours and hours staring at line after line...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.ryancoughlin.com/2008/11/04/validating-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
