<?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>Web Dev Bros &#187; Ruby on Rails</title>
	<atom:link href="http://www.webdevbros.net/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webdevbros.net</link>
	<description>hot talk about web development</description>
	<lastBuildDate>Thu, 20 Jan 2011 19:55:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Ruby Development Toolkit for Eclipse IDE &#124; RDT</title>
		<link>http://www.webdevbros.net/2009/06/14/ruby-development-toolkit-for-eclipse-ide-rdt/</link>
		<comments>http://www.webdevbros.net/2009/06/14/ruby-development-toolkit-for-eclipse-ide-rdt/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 16:17:25 +0000</pubDate>
		<dc:creator>julien</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[general stuff]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=256</guid>
		<description><![CDATA[I&#8217;ve been looking into Ruby and Rails recently since I deployed Redmine at my company to support our software development projects. For those who don&#8217;t know Redmine, this is a great piece of open-source software, offering a complete web collaborative solution for project management including source control, wiki, issues tracking, ldap authentication&#8230; Today, I just [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been looking into Ruby and Rails recently since I deployed <a href="http://www.redmine.org">Redmine</a> at my company to support our software development projects. For those who don&#8217;t know Redmine, this is a great piece of open-source software, offering a complete web collaborative solution for project management including source control, wiki, issues tracking, ldap authentication&#8230;</p>
<p>Today, I just found out there is a Ruby Development Toolkit (RDT) plugin for my favourite IDE&#8230; Eclipse! Sweet! The toolkit is downloadable via Eclipse Software Update, the remote site URL is:</p>
<p>http://updatesite.rubypeople.org/release</p>
<p>Features supported are syntax highlighting, on the fly syntax check, graphical outline, Test::Unit view/runner, Ruby application launching, content assist, source formatter, Ruby debugging, Type Hierarchy view, Ruby specific Search, Refactoring, and much, much more&#8230;</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2009/06/14/ruby-development-toolkit-for-eclipse-ide-rdt/&amp;t=Ruby+Development+Toolkit+for+Eclipse+IDE+%7C+RDT&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2009/06/14/ruby-development-toolkit-for-eclipse-ide-rdt/&amp;title=Ruby+Development+Toolkit+for+Eclipse+IDE+%7C+RDT&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2009/06/14/ruby-development-toolkit-for-eclipse-ide-rdt/&amp;title=Ruby+Development+Toolkit+for+Eclipse+IDE+%7C+RDT&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Ruby+Development+Toolkit+for+Eclipse+IDE+%7C+RDT;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2009/06/14/ruby-development-toolkit-for-eclipse-ide-rdt/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2009/06/14/ruby-development-toolkit-for-eclipse-ide-rdt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What&#8217;s new in Rails 2.1?</title>
		<link>http://www.webdevbros.net/2008/08/08/whats-new-in-rails-21/</link>
		<comments>http://www.webdevbros.net/2008/08/08/whats-new-in-rails-21/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 14:05:58 +0000</pubDate>
		<dc:creator>fab</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=209</guid>
		<description><![CDATA[If you want to know what&#8217;s new in Rails 2.1 or think that you may have missed a new feature, you should check out the e-book &#8220;Ruby on Rails 2.1. What&#8217;s new?&#8220;. There are all new features described with an example. It&#8217;s quite amazing to see how rails evolves. btw: did you know that there [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to know what&#8217;s new in Rails 2.1 or think that you may have missed a new feature, you should check out the e-book &#8220;<a href="http://www.nomedojogo.com/2008/06/09/new-free-book-ruby-on-rails-21-whats-new/">Ruby on Rails 2.1. What&#8217;s new?</a>&#8220;.</p>
<p>There are all new features described with an example. It&#8217;s quite amazing to see how rails evolves.<br />
btw: did you know that there is finally an <a href="http://www.artweb-design.de/2008/7/18/finally-ruby-on-rails-gets-internationalized">i18n patch in edge rails</a>, to be released with rails 2.2? this is a solid foundation for other plugins to build on.</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2008/08/08/whats-new-in-rails-21/&amp;t=What%27s+new+in+Rails+2.1%3F&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2008/08/08/whats-new-in-rails-21/&amp;title=What%27s+new+in+Rails+2.1%3F&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2008/08/08/whats-new-in-rails-21/&amp;title=What%27s+new+in+Rails+2.1%3F&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=What%27s+new+in+Rails+2.1%3F;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2008/08/08/whats-new-in-rails-21/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2008/08/08/whats-new-in-rails-21/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I love HAML</title>
		<link>http://www.webdevbros.net/2008/04/26/i-love-haml/</link>
		<comments>http://www.webdevbros.net/2008/04/26/i-love-haml/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 08:31:46 +0000</pubDate>
		<dc:creator>fab</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=175</guid>
		<description><![CDATA[Just a quick post to let everybody know that i&#8217;m switching my erb templates over to HAML. All my css with SASS will follow. These two template engines enhance my productivity a lot. it&#8217;s compatible with rails 2. I must admit that there are still some issues like: No ruby code on multiple lines to [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.webdevbros.net/wp-content/uploads/2008/04/haml1.png'><img src="http://www.webdevbros.net/wp-content/uploads/2008/04/haml1.png" alt="" title="haml1" width="160" height="151" class="alignleft size-medium wp-image-177" /></a>Just a quick post to let everybody know that i&#8217;m switching my erb templates over to <a href="http://haml.hamptoncatlin.com/">HAML</a>. All my css with SASS will follow. These two template engines enhance my productivity a lot. it&#8217;s compatible with rails 2.</p>
<p>I must admit that there are still some issues like: No ruby code on multiple lines to format the code properly on very long ruby statements. And: HAML source code highlighting in netbeans plugin is quite old and not updated, but this doesnt stop me from using it.</p>
<p>just checkout the &#8220;showdown&#8221; on the bottom of the first page to get a feeling of HAML.</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2008/04/26/i-love-haml/&amp;t=I+love+HAML&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2008/04/26/i-love-haml/&amp;title=I+love+HAML&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2008/04/26/i-love-haml/&amp;title=I+love+HAML&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=I+love+HAML;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2008/04/26/i-love-haml/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2008/04/26/i-love-haml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rounded div corners with Ruby on Rails</title>
		<link>http://www.webdevbros.net/2008/04/26/rounded-div-corners-with-ruby-on-rails/</link>
		<comments>http://www.webdevbros.net/2008/04/26/rounded-div-corners-with-ruby-on-rails/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 08:24:52 +0000</pubDate>
		<dc:creator>fab</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/?p=174</guid>
		<description><![CDATA[So now you know how to do nicely rounded div corners without using images or any javascript after reading this post. But how do we integrate this nicely into our rails app? The following solution might not be perfect but that's what i'm using and like: put the css file from Deathshadow in your public/stylesheets [...]]]></description>
			<content:encoded><![CDATA[<p>So now you know how to do nicely rounded div corners without using images or any javascript after reading <a href="/2008/04/24/rounded-corners-with-css-and-no-images/">this post</a>.</p>
<p>But how do we integrate this nicely into our rails app? The following solution might not be perfect but that's what i'm using and like:<br />
<span id="more-174"></span></p>
<p>put the <a href="http://battletech.hopto.org/html_tutorials/rounded_css_borders/screen_borderstyles.css">css file</a> from <a href="http://battletech.hopto.org/html_tutorials/rounded_css_borders/more_styles.html">Deathshadow</a><br />
in your public/stylesheets dir.</p>
<p>in your erb view, include the css with:</p>
<div class="igBar"><span id="lruby-7"><a href="#" onclick="javascript:showCodeTxt('ruby-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-7">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;%= stylesheet_link_tag <span style="color:#996600;">"screen_borderstyles"</span> %&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>then add the following helper methods to the entire application:</p>
<div class="igBar"><span id="lruby-8"><a href="#" onclick="javascript:showCodeTxt('ruby-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-8">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># in application_helper.rb we add:</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> rounded_div<span style="color:#006600; font-weight:bold;">&#40;</span>options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, &amp;block<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; start, ending = rounded_div_html_code<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; concat<span style="color:#006600; font-weight:bold;">&#40;</span>start, block.<span style="color:#CC0066; font-weight:bold;">binding</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; block.<span style="color:#9900CC;">call</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; concat<span style="color:#006600; font-weight:bold;">&#40;</span>ending, block.<span style="color:#CC0066; font-weight:bold;">binding</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> rounded_div_rb<span style="color:#006600; font-weight:bold;">&#40;</span>options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>, &amp;block<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; start, ending = rounded_div_html_code<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; start + block.<span style="color:#9900CC;">call</span> + ending</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> rounded_div_html_code<span style="color:#006600; font-weight:bold;">&#40;</span>options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; id_attrib = options<span style="color:#006600; font-weight:bold;">&#91;</span>:id<span style="color:#006600; font-weight:bold;">&#93;</span> ? <span style="color:#996600;">" id=<span style="color:#000099;">\"</span>#{options[:id]}<span style="color:#000099;">\"</span>"</span> : <span style="color:#996600;">""</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; class_attrib = options<span style="color:#006600; font-weight:bold;">&#91;</span>:<span style="color:#9966CC; font-weight:bold;">class</span><span style="color:#006600; font-weight:bold;">&#93;</span> ? <span style="color:#996600;">" #{options[:class]}"</span> : <span style="color:#996600;">""</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; border = options<span style="color:#006600; font-weight:bold;">&#91;</span>:border<span style="color:#006600; font-weight:bold;">&#93;</span> ? <span style="color:#996600;">"_border"</span> : <span style="color:#996600;">""</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span> %!</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &lt;div <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">"rounded#{border}#{class_attrib}"</span><span style="color:#008000; font-style:italic;">#{id_attrib}&gt;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;b <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">"top"</span>&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">"rounded_content"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; !,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; %!</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;b <span style="color:#9966CC; font-weight:bold;">class</span>=<span style="color:#996600;">"bottom"</span>&gt;&lt;b&gt;&lt;b&gt;&lt;b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;&lt;/b&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &lt;/div&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; !</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>to let this work we still need to definde the proper css classes as explained on the rounded corners web page:</p>
<div class="igBar"><span id="lcss-9"><a href="#" onclick="javascript:showCodeTxt('css-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CSS:</span>
<div id="css-9">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"># in your_stylesheet.css:</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.my_rounded_div .<span style="color: #000000; font-weight: bold;">top</span>,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.my_rounded_div <span style="color: #6666ff;">.<span style="color: #000000; font-weight: bold;">top</span> </span>b,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.my_rounded_div .<span style="color: #000000; font-weight: bold;">bottom</span>,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.my_rounded_div <span style="color: #6666ff;">.<span style="color: #000000; font-weight: bold;">bottom</span> </span>b,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">.my_rounded_div .rounded_content <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span>: #ffffff;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border-color</span>: <span style="color: #993333;">green</span>;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>now in any of your views you can do fun stuff like:</p>
<div class="igBar"><span id="lruby-10"><a href="#" onclick="javascript:showCodeTxt('ruby-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-10">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% rounded_div<span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">class</span> =&gt; <span style="color:#996600;">"my_rounded_div"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> %&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; This is the content of my rounded div. <span style="color:#9900CC;">Arbitrary</span> view code goes here.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% <span style="color:#9966CC; font-weight:bold;">end</span> %&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>or with a nice border around the div:</p>
<div class="igBar"><span id="lruby-11"><a href="#" onclick="javascript:showCodeTxt('ruby-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-11">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% rounded_div<span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">class</span> =&gt; <span style="color:#996600;">"my_rounded_div"</span>, :border =&gt; <span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> %&gt;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; This is the content of my rounded div with a border. <span style="color:#9900CC;">Arbitrary</span> view code goes here.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% <span style="color:#9966CC; font-weight:bold;">end</span> %&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>but also inside your view helpers you can generate rounded divs with pure ruby:</p>
<div class="igBar"><span id="lruby-12"><a href="#" onclick="javascript:showCodeTxt('ruby-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-12">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> display_category_helper<span style="color:#006600; font-weight:bold;">&#40;</span>category<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; rounded_div_rb<span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#9966CC; font-weight:bold;">class</span> =&gt; <span style="color:#996600;">"main-cat"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; link_to<span style="color:#006600; font-weight:bold;">&#40;</span>h<span style="color:#006600; font-weight:bold;">&#40;</span>category.<span style="color:#9900CC;">name</span><span style="color:#006600; font-weight:bold;">&#41;</span>, category_path<span style="color:#006600; font-weight:bold;">&#40;</span>category<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2008/04/26/rounded-div-corners-with-ruby-on-rails/&amp;t=Rounded+div+corners+with+Ruby+on+Rails&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2008/04/26/rounded-div-corners-with-ruby-on-rails/&amp;title=Rounded+div+corners+with+Ruby+on+Rails&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2008/04/26/rounded-div-corners-with-ruby-on-rails/&amp;title=Rounded+div+corners+with+Ruby+on+Rails&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Rounded+div+corners+with+Ruby+on+Rails;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2008/04/26/rounded-div-corners-with-ruby-on-rails/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2008/04/26/rounded-div-corners-with-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>picnik comes with a free-to-use image editing API for your website</title>
		<link>http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/</link>
		<comments>http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 03:32:11 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[classic ASP (VBScript)]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/</guid>
		<description><![CDATA[Ever heard from Picnik? It allows you editing your images direclty within your browser. Forget Adobe Photoshop :) Picnik has been around for a while now but recently it started to offer its service for the public. for free! I played around a bit and must say that it is amazing .. Use it within [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://www.webdevbros.net/wp-content/uploads/2008/01/picnic.gif' alt='picnic.gif' style="float:left"/> Ever heard from <a href="http://www.picnik.com">Picnik</a>? It allows you editing your images direclty within your browser. Forget Adobe Photoshop :) Picnik has been around for a while now but recently it started to offer its service for the public. for free! I played around a bit and must say that it is amazing .. Use it within PHP, classic ASP, .net, Ruby on Rails  or whatever... especially i like the idea of the whole service which works like this...</p>
<ol>
<li>Send your images to their service (existing image via URL or encoded as multi-part)</li>
<li>Then the user modifies the picture (size, colors, rotation, special effects...)</li>
<li>Picnik sends you the picture back to your server (either an URL where you can download it or directly as multi-part image)</li>
</ol>
<p>Here comes an example I have built for demonstration...<span id="more-149"></span>Click on the picture below to edit it.</p>
<p><a href="http://www.picnik.com/service/?_apikey=178ef7667a0c301dd8eb89e76caba626&#038;_import=http%3A//www.webdevbros.net/wp-content/uploads/2008/01/googleapple.jpg&#038;_export=http%3A//www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website&#038;_export_title=back%20to%20webdevbros"><img src='http://www.webdevbros.net/wp-content/uploads/2008/01/googleapple.jpg' alt='googleapple.jpg' /></a></p>
<p>Everything realized by using a link to this URL:</p>
<div class="igBar"><span id="lhtml-14"><a href="#" onclick="javascript:showCodeTxt('html-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-14">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">http://www.picnik.com/service/</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ?_apikey=178ef7667a0c301dd8eb89e76caba626</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #ddbb00;">&amp;_import=http%3A//www.webdevbros.net/wp-content/uploads/2008/01/googleapple.jpg</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &amp;_export=http%3A//www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &amp;_export_title=back%20to%20webdevbros </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Pretty cool isn't it? Thats the basic example but you can customize a lot more (see their <a href="http://www.picnik.com/info/api/reference">API</a>). Also I didn't progress the picture back on my server.</p>
<p>If you want to get started i recommend to start with their <a href="http://www.picnik.com/info/api/tutorials">tutorials</a>. They are nicely written and done in 10 minutes.</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/&amp;t=picnik+comes+with+a+free-to-use+image+editing+API+for+your+website&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/&amp;title=picnik+comes+with+a+free-to-use+image+editing+API+for+your+website&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/&amp;title=picnik+comes+with+a+free-to-use+image+editing+API+for+your+website&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=picnik+comes+with+a+free-to-use+image+editing+API+for+your+website;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2008/01/23/picnik-comes-with-a-free-to-use-image-editing-api-for-your-website/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>automatically strip attributes of an ActiveRecord model</title>
		<link>http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/</link>
		<comments>http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 10:10:14 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/</guid>
		<description><![CDATA[You know the situation when some users add a couple of whitespaces to the front or/and the end of a value they just entered into your application? Yeah, and in most cases we dont really want those blanks in our data. But on the other hand we can not really blame them because sometimes it [...]]]></description>
			<content:encoded><![CDATA[<p>You know the situation when some users add a couple of whitespaces to the front or/and the end of a value they just entered into your application? Yeah, and in most cases we dont really want those blanks in our data. But on the other hand we can not really blame them because sometimes it just happens by mistake. Just imagine your cat played with the space bar while you quickly went for a coffee. The solution is not to get rid of the cat, ... Its rahter an extension. And no not to your cat - small extension to <code>ActiveRecord</code><span id="more-148"></span></p>
<p>Bung this snippet into a file in your applications <code>lib</code> folder and don't forget to <code>require</code> it within the <code>environment.rb</code> (Alternatively you could use the new initializers of Rails 2.0).</p>
<div class="igBar"><span id="lruby-17"><a href="#" onclick="javascript:showCodeTxt('ruby-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-17">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> Base</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#strips the value of the given attributes automatically</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">auto_strip</span><span style="color:#006600; font-weight:bold;">&#40;</span>*attrs<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; attrs.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |attr|</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; define_method<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span>attr.<span style="color:#9900CC;">to_s</span> + '='<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |val| write_attribute attr, val.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">strip</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>After that you can do the following to your <code>ActiveRecord</code> models:</p>
<div class="igBar"><span id="lruby-18"><a href="#" onclick="javascript:showCodeTxt('ruby-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-18">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> User &lt;ActiveRecord::Base</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; auto_strip :firstname, :lastname</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now the attributes <code>firstname</code> and <code>lastname</code> will never ever hold values including whitespaces in front and the end. Note: the cat is still alive ...</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/&amp;t=automatically+strip+attributes+of+an+ActiveRecord+model&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/&amp;title=automatically+strip+attributes+of+an+ActiveRecord+model&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/&amp;title=automatically+strip+attributes+of+an+ActiveRecord+model&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=automatically+strip+attributes+of+an+ActiveRecord+model;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2008/01/22/automatically-strip-attributes-of-an-activerecord-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Special chars like e.g. {~ are not supported within rails console on windows</title>
		<link>http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/</link>
		<comments>http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 21:02:26 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[general stuff]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/</guid>
		<description><![CDATA[When working with Ruby on Rails on a windows machine you will sometimes need the development console or the interactive ruby console (irb). Actually you need it quite often :) If you do so you'll discover that special character like the tilde (~) or the {}-brackets are not supported there. Why? I don't know but [...]]]></description>
			<content:encoded><![CDATA[<p>When working with Ruby on Rails on a windows machine you will sometimes need the development console or the interactive ruby console (irb). Actually you need it quite often :) If you do so you'll discover that special character like the tilde (~) or the {}-brackets are not supported there. Why? I don't know but let me know if you know the reason. However, to solve this problem just create a file which has the following content:</p>
<p><code><br />
"\M-[": "["<br />
"\M-]": "]"<br />
"\M-{": "{"<br />
"\M-}": "}"<br />
"\M-\\": "\\"<br />
"\M-|": "|"<br />
"\M-@": "@"<br />
"\M-~": "~"<br />
"\M-?": "?"<br />
</code></p>
<p>save this to e.g. <code>c:\.inputrc</code> and put the following to your <code>irb.bat</code> (which is usually located in <code>c:\ruby\bin\</code>) straight after the <code>@echo off</code> line:</p>
<p><code>SET INPUTRC=C:\.inputrc</code></p>
<p>Now you should be a more happier Rails dev.. At least i am. (I found this information at <a href="http://flip.netzbeben.de/2007/07/28/rails-12-fehlender-zeichensatz-in-der-console-irb/">flip's blog</a> - Thanks!)</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/&amp;t=Special+chars+like+e.g.+%7B%7E+are+not+supported+within+rails+console+on+windows&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/&amp;title=Special+chars+like+e.g.+%7B%7E+are+not+supported+within+rails+console+on+windows&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/&amp;title=Special+chars+like+e.g.+%7B%7E+are+not+supported+within+rails+console+on+windows&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Special+chars+like+e.g.+%7B%7E+are+not+supported+within+rails+console+on+windows;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/12/20/special-chars-like-eg-are-not-supported-within-rails-console-on-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Want to show your source code to someone else?</title>
		<link>http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/</link>
		<comments>http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 15:47:13 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/</guid>
		<description><![CDATA[Today i stumbled across a nice tool called Pastie. Pastie helps you if you want to show some bits of your source code to someone else. e.g. you need some help, advice (or you just want to show off with your code). You paste an excerpt of your code and pastie saves it for under [...]]]></description>
			<content:encoded><![CDATA[<p>Today i stumbled across a nice tool called <a href="http://pastie.caboo.se/">Pastie</a>. Pastie helps you if you want to show some bits of your source code to someone else. e.g. you need some help, advice (or you just want to show off with your code). You paste an excerpt of your code and pastie saves it for under a unique URL. Then you send this URL to the person you want to show the code. The big advantage here is that the syntax is nicely highlighted ... very nice for remote troubleshooting! I have created a <a href="http://pastie.caboo.se/129609">code snippet</a> for demonstration.</p>
<p><img src='http://www.webdevbros.net/wp-content/uploads/2007/12/pastie.jpg' alt='pastie.jpg' /><br />
(i've used <a href="http://pastie.caboo.se/help/">code sections</a> to create more sections.)</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/&amp;t=Want+to+show+your+source+code+to+someone+else%3F&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/&amp;title=Want+to+show+your+source+code+to+someone+else%3F&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/&amp;title=Want+to+show+your+source+code+to+someone+else%3F&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Want+to+show+your+source+code+to+someone+else%3F;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/12/17/want-to-show-your-source-code-to-someone-else/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bulk testing your model attributes with rails</title>
		<link>http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/</link>
		<comments>http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 11:20:39 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/</guid>
		<description><![CDATA[When it comes to testing in Ruby on Rails I tend to test every piece of its public interface. This means I test every single public method and attribute to ensure my desired functionality. Recently I've updated my application from Rails 1.2.5 to 2.0.1 and I was happy to have tests. None of them failed [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to testing in Ruby on Rails I tend to test every piece of its public interface. This means I test every single public method and attribute to ensure my desired functionality. Recently I've updated my application from Rails 1.2.5 to <a href="http://weblog.rubyonrails.org/2007/12/7/rails-2-0-it-s-done">2.0.1</a> and I was happy to have tests. None of them failed and so I knew that my application is ready to rock with the new Rails 2.0.<br />
However, what I want to write in this article about is how to do bulk testing of each single attribute of your models. Let's be a bit precise. Say we have a model <code>User</code> which has attributes <code>firstname</code>, <code>lastname</code>and <code>age</code>. In order to perfectly test the <code>User</code> model we should write tests which ...</p>
<ol>
<li>ensure that invalid values result in an error for the tested attribute (e.g. age -2 is invalid, so the instance should hold an error for the attribute <code>age</code>)</li>
<li>and valid values don't result in an error for the tested attribute (e.g. age 20 should be fine)</li>
</ol>
<p>Usually you should test a couple of invalid values and a couple of valid values against each attribute of your model. This can be quite a lot to code. I explain a nice approach how to speed things up and save time for the next family event.<span id="more-130"></span></p>
<p>(Code below has been tested with Rails 1.2.5 and Rails 2.0.1) Let's say our User class looks the following:</p>
<div class="igBar"><span id="lruby-24"><a href="#" onclick="javascript:showCodeTxt('ruby-24'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-24">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> User &lt;ActiveRecord::Base</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; validates_length_of :firstname, :<span style="color:#9966CC; font-weight:bold;">in</span> =&gt; <span style="color:#006666;color:#800000;">2</span>..<span style="color:#006666;color:#800000;">255</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; validates_length_of :lastname, :<span style="color:#9966CC; font-weight:bold;">in</span> =&gt; <span style="color:#006666;color:#800000;">3</span>..<span style="color:#006666;color:#800000;">255</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; validates_numericality_of :age, :only_integer =&gt; <span style="color:#0000FF; font-weight:bold;">true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; protected</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> validate</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; errors.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>:age, <span style="color:#996600;">"must be greater 0 and maximum 100"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> age.<span style="color:#0000FF; font-weight:bold;">nil</span>? || <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;color:#800000;">1</span>..<span style="color:#006666;color:#800000;">100</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>age<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>I don't go too much into detail about this. Simply: It's a <code>User</code> which is bound to a <code>Users</code> database table and includes three validations:</p>
<ul>
<li>the firstname should have at least 2 chars and maximum 255</li>
<li>the firstname should have at least 3 chars and maximum 255</li>
<li>the age must be a number greater than 0 and maximum 100</li>
</ul>
<p>Best case would be if we completele test the <code>User</code> model for the following cases (testing that wrong values fail and correct values don't fail):</p>
<ul>
<li>valid firstnames: <code>michal, tom, John, Jennifer K, David</code></li>
<li>invalid firstname: 	<code>nil, J, ''</code></li>
<li>valid lastnames: <code>gabrukiewicz, Aniston, Heinemeier Hansson</code></li>
<li>invalid lastnames: <code>nil, gr, t, ''</code></li>
<li>valid ages: <code>1, 10, 20, 73</code></li>
<li>invalid ages: <code>nil, '', 0, -10, -36, x, 7sz, 101, 120</code></li>
<li>creating a valid User and successfully saving (not described in this article)</li>
<li>get an existing user, modify some attributes and save (not described in this article))</li>
</ul>
<p>Here we defined what is wrong and what not (what is even better: you could write this tests even before you write your <code>User</code> model). In order to do the bulk testing I have written a helper method which will do the stuff for us in a Rails-way. We put this method into our <code>test_helper.rb</code> so its available to all our test cases:</p>
<div class="igBar"><span id="lruby-25"><a href="#" onclick="javascript:showCodeTxt('ruby-25'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-25">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#tests ONE attribute of the tested model (@model must be set in setup method of the testcase) against given values.</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#expecting: what do we expect the values to be (:valid or :invalid)</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#attr: the tested attribute (provide an array if the error key differs from the attribute name)</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#vals: the values you want to test against</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>expecting, attr, vals<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#CC0066; font-weight:bold;">raise</span> ArgumentError, 'model must be set to the testing model' <span style="color:#9966CC; font-weight:bold;">if</span> @model.<span style="color:#9900CC;">blank</span>?</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; key = att = attr</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; att, key = attr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>, attr<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">if</span> attr.<span style="color:#9900CC;">is_a</span>? <span style="color:#CC0066; font-weight:bold;">Array</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; vals.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |v|</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m = @model.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>att =&gt; v<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; m.<span style="color:#9900CC;">valid</span>?</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; errors = m.<span style="color:#9900CC;">errors</span>.<span style="color:#9900CC;">on</span><span style="color:#006600; font-weight:bold;">&#40;</span>key<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> expecting == :valid</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; assert errors.<span style="color:#0000FF; font-weight:bold;">nil</span>?, <span style="color:#996600;">"'#{v}' should be a valid #{att.to_s} (#{errors})"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; assert !errors.<span style="color:#0000FF; font-weight:bold;">nil</span>?, <span style="color:#996600;">"'#{v}' should be an invalid #{att.to_s}"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>You see that the method expects the attribute we want to test (<code>attr</code>), the tested values (<code>vals</code>) and what we expect the values to be (<code>expecting</code>) - valid or invalid. Furthermore you see that the tested model is taken from the instance variable (<code>@model</code>) which will be taken from your individual test case (placed into the <code>setup</code> method). Thats to stick with DRY (cause every unit test deals with one model). Last but not least the helper <strong>asserts with a nice error message</strong> which eases us up to find the problem .. if there is one.<br />
Ok enough, we can use this now for the test of our <code>User</code>. Rails generated the <code>UserTest</code> for us when we generated the model. We test our attributes <code>firstname</code>, <code>lastname</code> and <code>age</code>. All for validity and invalidity.</p>
<div class="igBar"><span id="lruby-26"><a href="#" onclick="javascript:showCodeTxt('ruby-26'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-26">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> UserTest &lt;Test::Unit::TestCase</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> setup</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; @model = User</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_firstname</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:valid, :firstname, <span style="color:#006600; font-weight:bold;">&#91;</span>'michal', 'tom', 'John', 'Jennifer K', 'David'<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:invalid, :lastname, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, 'J', ''<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Thats nice but at this point we stop. We are not testing <code>lastname</code> and <code>age</code> anymore because before we do so we DRY this a bit up. We add another helper method which uses our existing <code>attr_test</code> and tests the invalid and valid values in one go. After that we sit back and watch our tests run. Bung this method into your <code>test_helper.rb</code> ..</p>
<div class="igBar"><span id="lruby-27"><a href="#" onclick="javascript:showCodeTxt('ruby-27'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-27">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#this checks valid and invalid attributes in one go.</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#- check attr_test to understand more details if necessary</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>attr, values<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:invalid, attr, values<span style="color:#006600; font-weight:bold;">&#91;</span>:invalid<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:valid, attr, values<span style="color:#006600; font-weight:bold;">&#91;</span>:valid<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>with this we are ready to rock our <code>User</code> class. See the full test now...</p>
<div class="igBar"><span id="lruby-28"><a href="#" onclick="javascript:showCodeTxt('ruby-28'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-28">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> UserTest &lt;Test::Unit::TestCase</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> setup</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; @model = User</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_firstname</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:firstname,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:valid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span>'michal', 'tom', 'John', 'Jennifer K', 'David'<span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:invalid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, 'J', ''<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_lastname</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:lastname,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:valid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span>'gabrukiewicz', 'Aniston', 'Heinemeier Hansson'<span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:invalid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, 'gr', 't', ''<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> test_age</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; bulk_attr_test<span style="color:#006600; font-weight:bold;">&#40;</span>:age,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:valid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">1</span>, <span style="color:#006666;color:#800000;">10</span>, <span style="color:#006666;color:#800000;">20</span>, <span style="color:#006666;color:#800000;">73</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&nbsp; &nbsp;:invalid =&gt; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">nil</span>, '', <span style="color:#006666;color:#800000;">0</span>, -<span style="color:#006666;color:#800000;">10</span>, -<span style="color:#006666;color:#800000;">36</span>, x, 7sz, <span style="color:#006666;color:#800000;">101</span>, <span style="color:#006666;color:#800000;">120</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>That's it if the tests were successful then your model is working fine. If not then you will see helpful messages in your console which will indicate what went wrong during the attributes test.</p>
<p>I strongly recommend you to test all your models against the functionality you will use in your application(s) (all public class members). This takes a bit of time but it let's you sleep better after doing any upgrades, enhancements, bug fixes etc. And don't forget: never cheat on yourself when writing tests! you are writing them for you ...</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/&amp;t=Bulk+testing+your+model+attributes+with+rails&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/&amp;title=Bulk+testing+your+model+attributes+with+rails&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/&amp;title=Bulk+testing+your+model+attributes+with+rails&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Bulk+testing+your+model+attributes+with+rails;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/12/12/bulk-testing-of-your-model-attributes-with-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extended Email validation for all your models (validates_email)</title>
		<link>http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/</link>
		<comments>http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 16:31:01 +0000</pubDate>
		<dc:creator>Michal</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/</guid>
		<description><![CDATA[Ruby on Rails ships with a lot of predefined validations for your models. Unfortunately there is no special email validation. Even Rails 2.0 does not ship it (check the ActiveRecord changelog) yet. Because I needed it I had to write my own validates_email method. I know there are a lot of plugins but non of [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby on Rails ships with a lot of predefined validations for your models. Unfortunately there is no special email validation. Even Rails 2.0 does not ship it (check the <code>ActiveRecord</code> <a href="http://dev.rubyonrails.org/svn/rails/tags/rel_2-0-0_RC2/activerecord/CHANGELOG">changelog</a>) yet. Because I needed it I had to write my own <code>validates_email</code> method. I know there are a lot of plugins but non of them suits my needs. <code>validates_email</code> does the following:</p>
<ul>
<li>checks if email is syntactically correct (using regex)</li>
<li>checks if the host of the email is supported within the application. This is very important for me because I dont want ppl signing up with one-time emails from e.g. <a href="http://www.mailinator.com">mailinator.com</a>. (can be disabled)</li>
</ul>
<p><span id="more-125"></span></p>
<p>For this we create a validations helper module which holds all our custom validations. We can then inject them into our models where necessary. The following code should live in <code>/helpers/validations_helper.rb</code> in order to be loaded automatically:</p>
<div class="igBar"><span id="lruby-31"><a href="#" onclick="javascript:showCodeTxt('ruby-31'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-31">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#Michal Gabrukiewicz</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#helpers for validating ActiveRecord instances</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;">#- load with 'extend' within your model</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">module</span> ValidationsHelper</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; EMAIL_PATTERN = /^<span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>\w\.-<span style="color:#006600; font-weight:bold;">&#93;</span>*<span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z0-<span style="color:#006666;color:#800000;">9</span>_<span style="color:#006600; font-weight:bold;">&#93;</span>@<span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z0-<span style="color:#006666;color:#800000;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>\w\.-<span style="color:#006600; font-weight:bold;">&#93;</span>*<span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z0-<span style="color:#006666;color:#800000;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>\.<span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z\.<span style="color:#006600; font-weight:bold;">&#93;</span>*<span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z<span style="color:#006600; font-weight:bold;">&#93;</span>$/</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; DISALLOWED_EMAIL_HOSTS = %w<span style="color:#006600; font-weight:bold;">&#40;</span>mailinator.<span style="color:#9900CC;">com</span> mailinator.<span style="color:#9900CC;">org</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;">#validates if given attributes are syntactically valid emails</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;">#- last parameter can be a hash with options</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;">#&nbsp; &nbsp;- :allow_all_hosts indicates if every host is allowed. if false then its checked</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;">#&nbsp; &nbsp; &nbsp;against the list DISALLOWED_EMAIL_HOSTS and returns fals if the email is</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#008000; font-style:italic;">#&nbsp; &nbsp; &nbsp;from one of those. default = false</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> validates_email<span style="color:#006600; font-weight:bold;">&#40;</span>*attrs<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; config = <span style="color:#006600; font-weight:bold;">&#123;</span>:message =&gt; 'is no valid email address', :on =&gt; :save, :allow_all_hosts =&gt; <span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; config.<span style="color:#9900CC;">update</span><span style="color:#006600; font-weight:bold;">&#40;</span>attrs.<span style="color:#9900CC;">pop</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> attrs.<span style="color:#9900CC;">last</span>.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>Hash<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; validates_each<span style="color:#006600; font-weight:bold;">&#40;</span>attrs, config<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |record, attr, value|</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">unless</span> config<span style="color:#006600; font-weight:bold;">&#91;</span>:<span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#9966CC; font-weight:bold;">not</span> evaluate_condition<span style="color:#006600; font-weight:bold;">&#40;</span>config<span style="color:#006600; font-weight:bold;">&#91;</span>:<span style="color:#9966CC; font-weight:bold;">if</span><span style="color:#006600; font-weight:bold;">&#93;</span>, record<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;">#do every check only if there was no error yet...</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; error = <span style="color:#0000FF; font-weight:bold;">false</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; error = record.<span style="color:#9900CC;">errors</span>.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>attr, config<span style="color:#006600; font-weight:bold;">&#91;</span>:message<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#9966CC; font-weight:bold;">not</span> error <span style="color:#9966CC; font-weight:bold;">and</span> value =~ EMAIL_PATTERN</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; error = record.<span style="color:#9900CC;">errors</span>.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span>attr, config<span style="color:#006600; font-weight:bold;">&#91;</span>:message<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> config<span style="color:#006600; font-weight:bold;">&#91;</span>:allow_all_hosts<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#9966CC; font-weight:bold;">not</span> error <span style="color:#9966CC; font-weight:bold;">and</span> DISALLOWED_EMAIL_HOSTS.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>value.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"@"</span>, <span style="color:#006666;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">strip</span>.<span style="color:#9900CC;">downcase</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>If you now want to validate e.g. the <code>email</code> attribute of a <code>User</code> model, do it like you used to do with the existing validators:</p>
<div class="igBar"><span id="lruby-32"><a href="#" onclick="javascript:showCodeTxt('ruby-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">RUBY:</span>
<div id="ruby-32">
<div class="ruby">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> User</div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; extend ValidationsHelper</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; </div>
</li>
<li style="font-weight: bold;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; validates_email :email</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#767676;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It still supports all the options which you know from all other validators. So you can specify your own message with <code>:message</code>, use  a condition with <code>:if</code>, etc. There is one additional option <code>:allow_all_hosts</code> which prevents the validator to check against the disallowed hosts (all email hosts would be allowed then).</p>
<p>have fun with it and feel free to comment improvements, suggestions, comlaints, etc... </p>
<p>if you are looking for more validators and/or more information about them check <a href="http://www.railsdev.ws/blog/11/custom-validations-in-rails/" target="_blank">Custom validations in rails from Greg</a></p>
<p>michal - RaRoR (rock and roll ruby on rails)</p>
<div><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/&amp;t=Extended+Email+validation+for+all+your+models+%28validates_email%29&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td> <td><iframe src='http://www.reddit.com/button_content?newwindow=1&amp;url=http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/&amp;title=Extended+Email+validation+for+all+your+models+%28validates_email%29&amp;t=2 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/&amp;title=Extended+Email+validation+for+all+your+models+%28validates_email%29&amp;t=1 ' height='80' width='52' scrolling='no' frameborder='0' ></iframe></td> <td><script type="text/javascript"><!--yahooBuzzArticleHeadline=Extended+Email+validation+for+all+your+models+%28validates_email%29;//--></script><script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype=square></script></td> <td><script type="text/javascript">tweetmeme_url='http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/'; tweetmeme_style = 'normal';; </script><script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js" ></script></td></table></div><!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	-->]]></content:encoded>
			<wfw:commentRss>http://www.webdevbros.net/2007/12/05/email-validation-for-your-models-validates_email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

