<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Rails Playground</title>
	
	<link>http://blog.railsjaipur.in</link>
	<description>Adore Web 2.0, Ruby on Rails</description>
	<lastBuildDate>Tue, 01 Jun 2010 11:39:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/RailsPlayground" /><feedburner:info uri="railsplayground" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Flash Player Helper [Plugin for Rails]</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/PuWkwXzyqk0/</link>
		<comments>http://blog.railsjaipur.in/2010/06/flash-player-helper-plugin-for-rails/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 11:36:05 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Views]]></category>

		<guid isPermaLink="false">http://blog.railsjaipur.in/?p=154</guid>
		<description><![CDATA[What Is It?
Flash player Helper is a Rails plugin that presents an ActionView wrapper for rendering JW Flash Player 5.1 and Image Rotator
JW Flash Player is a popular open source Media player that supports most media formats. This Plugin is also backward compatible for version lesser than 5.1.
To use it you need to install plugin [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What Is It?</strong></p>
<p>Flash player Helper is a Rails plugin that presents an ActionView wrapper for rendering <a href="http://www.longtailvideo.com/players/jw-flv-player/">JW Flash Player 5.1</a> and <a href="http://www.longtailvideo.com/players/jw-image-rotator/">Image Rotator</a></p>
<p>JW Flash Player is a popular open source Media player that supports most media formats. This Plugin is also backward compatible for version lesser than 5.1.</p>
<p>To use it you need to install plugin by running</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code9'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1549"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code9"><pre class="ruby" style="font-family:monospace;">script<span style="color:#006600; font-weight:bold;">/</span>plugin install git:<span style="color:#006600; font-weight:bold;">//</span>github.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>bagwanpankaj<span style="color:#006600; font-weight:bold;">/</span>flash_player_helper.<span style="color:#9900CC;">git</span></pre></td></tr></table></div>

<p>This will automatically setup JW Flash Player for your rails application. It also installs required files under public folder.</p>
<p>If required files are not copied autometically under public directory then you can copy them by running</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code10'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15410"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code10"><pre class="ruby" style="font-family:monospace;">rake flash_player:install</pre></td></tr></table></div>

<p>How to use</p>
<p>Include swfobject javascript into layout or view file</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code11'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15411"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code11"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">'swfobject'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>Now to use flash player</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code12'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15412"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code12"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= player<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>See here, no parameter are passed, so it works with all default parameters. only file parameter in flashvar is needed to be passed.</p>
<p>and for Image Rotator</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code13'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15413"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code13"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>= image_rotator<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>The above command will render flash player or Image rotator with default configuration.<br />
The helper method for flah player looks like:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code14'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15414"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code14"><pre class="ruby" style="font-family:monospace;">player<span style="color:#006600; font-weight:bold;">&#40;</span>player_options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>,config = <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></pre></td></tr></table></div>

<p>and for Image Rotator</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code15'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15415"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code15"><pre class="ruby" style="font-family:monospace;">image_rotator<span style="color:#006600; font-weight:bold;">&#40;</span>player_options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>,config = <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></pre></td></tr></table></div>

<p>In which *player_options* contains options that you can pass for JW Flash Player, including flashvars supported by adobe flash.<br />
Note: all the flashvars should be passed under :flahvars key in player_options as a hash like</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p154code16'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p15416"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p154code16"><pre class="ruby" style="font-family:monospace;">@<span style="color:#006600; font-weight:bold;">&lt;%</span>= player<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:allowfullscreen</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'true'</span>,:allowscriptaccess <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'true'</span>,<span style="color:#006600; font-weight:bold;">&#123;</span>:flashvars <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:skin <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/swf/skins/bekle.swf'</span>, <span style="color:#ff3333; font-weight:bold;">:height</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'600'</span>, <span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/sample.flv'</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>You can find list of supported flashvars for Flash Player <a href="http://developer.longtailvideo.com/trac/wiki/Player5FlashVars">here</a> and flashvars for Image Rotator can be found <a href="http://developer.longtailvideo.com/trac/wiki/ImageRotatorVars">here</a></p>
<p>It supports skin in both format either you can pass zip file or a swf file to skin flashvars.</p>
<p>Note: Given relative path should be relative to public folder of your application.</p>
<p><strong>Credits</strong></p>
<p>Credit for this plugin goes to JW Flash Player Team for making such a awsome flash player.</p>
<p><strong>Future Addons</strong></p>
<p>Adding Flash Chart functionality to this plugin.</p>
<p><strong>More Info</strong><br />
Being very I am anable to provide detailed info here.<br />
For any specific query or info you can write me at &#8216;bagwanpankaj[_at_]railsjaipur.in&#8217;</p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/PuWkwXzyqk0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2010/06/flash-player-helper-plugin-for-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2010/06/flash-player-helper-plugin-for-rails/</feedburner:origLink></item>
		<item>
		<title>JW Silverlight Player Helper for Rails</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/kdr0w5PZoO4/</link>
		<comments>http://blog.railsjaipur.in/2010/05/jw-silverlight-player-helper-for-rails/#comments</comments>
		<pubDate>Tue, 04 May 2010 11:01:18 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[ActionView]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Tricks]]></category>
		<category><![CDATA[Views]]></category>

		<guid isPermaLink="false">http://blog.railsjaipur.in/?p=147</guid>
		<description><![CDATA[Recently while working on a project I needed to add JW Silverlight player. But I found it difficult to manually setup every thing. so to I started to build it in ruby way and extrated the code to make it plugin.
Silverlight Player Helper provides you an Action View Helper method available to all views and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently while working on a project I needed to add JW Silverlight player. But I found it difficult to manually setup every thing. so to I started to build it in ruby way and extrated the code to make it plugin.</p>
<p>Silverlight Player Helper provides you an Action View Helper method available to all views and provides all required files that are needed to build the player.</p>
<p>JW Silverlight Player supports wmv, wma and mp3 file formats. List of all supported format can be found <a href="http://developer.longtailvideo.com/trac/wiki/SilverlightFormats" target="_blank">here</a></p>
<h3>How To Use</h3>
<p>To use silverlight_player_helper you first need to install it as a plugin</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p147code20'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14720"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p147code20"><pre class="ruby" style="font-family:monospace;">  script<span style="color:#006600; font-weight:bold;">/</span>plugin install git:<span style="color:#006600; font-weight:bold;">//</span>github.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>bagwanpankaj<span style="color:#006600; font-weight:bold;">/</span>silverlight_player_helper.<span style="color:#9900CC;">git</span></pre></td></tr></table></div>

<p>And you are done. This command will automatically copies all required files to default folers under your public folder.<br />
If it doesn&#8217;t do it automatically then run:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p147code21'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14721"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p147code21"><pre class="ruby" style="font-family:monospace;">  rake sl_player:install</pre></td></tr></table></div>

<p>this rake task will copies all files to required folders.</p>
<p>Now to use this plugin write</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p147code22'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p14722"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p147code22"><pre class="ruby" style="font-family:monospace;">  <span style="color:#006600; font-weight:bold;">&lt;%</span>= jw_silverlight_player<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/path/to/your/file.wmv'</span>,:width <span style="color:#006600; font-weight:bold;">=&gt;</span> 640, <span style="color:#ff3333; font-weight:bold;">:height</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">480</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></td></tr></table></div>

<p>The minimum required options are nothing. If no file is provided then it runs default file (supplied with plugin).<br />
You can provide all options supported by JW Silverlight Player. These options can be found <a href="http://developer.longtailvideo.com/trac/wiki/SilverlightVars" target="_blank">here</a></p>
<p>For more info write me at<br />
bagwan.pankaj[_at_]railsjaipur.in</p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/kdr0w5PZoO4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2010/05/jw-silverlight-player-helper-for-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2010/05/jw-silverlight-player-helper-for-rails/</feedburner:origLink></item>
		<item>
		<title>Metaprogramming in Rails</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/gRGw8muFGSY/</link>
		<comments>http://blog.railsjaipur.in/2010/04/metaprogramming-in-rails/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 11:05:38 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[metaprogramming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://blog.railsjaipur.in/?p=125</guid>
		<description><![CDATA[Meta-programming means your programming language is writing code for you. And for sure Ruby is a great language having all cool features.Rails being a great ruby framework encashes all features of ruby. Rails itself uses meta-programming every where.
For example in ActiveRecord, we have dynamic method on attributes name like

?View Code RUBY1
2
3
find_by_something&#40;some_possible_values&#41;
find_all_by_something&#40;spv&#41;
find_by_something_and_otherthing&#40;some_value, other_value&#41;

In this topic we [...]]]></description>
			<content:encoded><![CDATA[<p>Meta-programming means your programming language is writing code for you. And for sure Ruby is a great language having all cool features.Rails being a great ruby framework encashes all features of ruby. Rails itself uses meta-programming every where.</p>
<p>For example in ActiveRecord, we have dynamic method on attributes name like</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code30'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12530"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p125code30"><pre class="ruby" style="font-family:monospace;">find_by_something<span style="color:#006600; font-weight:bold;">&#40;</span>some_possible_values<span style="color:#006600; font-weight:bold;">&#41;</span>
find_all_by_something<span style="color:#006600; font-weight:bold;">&#40;</span>spv<span style="color:#006600; font-weight:bold;">&#41;</span>
find_by_something_and_otherthing<span style="color:#006600; font-weight:bold;">&#40;</span>some_value, other_value<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>In this topic we will see how we can meta-program in Rails. Using Meta Programming one can reduce LOC to dramatic level and it also reduce headache in maintaining code base.</p>
<p>Here I am not going into details for class_eval and instanse_eval because there are many blog post out there. But I do give some examples.</p>
<p>Consider following:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code31'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12531"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p125code31"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Testt
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Testt.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> foo
    <span style="color:#996600;">&quot;I'll be available as instance method&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">foo</span>
    <span style="color:#996600;">&quot;I'll be available as class method&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Testt.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">foo</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> I<span style="color:#996600;">'ll be available as instance method
Testt.foo
=&gt;I  be available as class method</span></pre></td></tr></table></div>

<p>Let me explain that class_eval evaluates a string or code block in context of class or module it is called upon.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code32'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12532"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p125code32"><pre class="ruby" style="font-family:monospace;">Testt.<span style="color:#9900CC;">instance_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> foo
    <span style="color:#996600;">&quot;I'll be available as class method&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">bar</span>
    <span style="color:#996600;">&quot;I'll be available as class method&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
Testt.<span style="color:#9900CC;">foo</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span>I<span style="color:#996600;">'ll be available as class method
Testt.bar
=&gt;I'</span>ll be available as <span style="color:#9966CC; font-weight:bold;">class</span> method</pre></td></tr></table></div>

<p>instance_eval can evaluate a string or a code block in the context of the receiver.</p>
<p>The third way to define a method in class or module is define_method.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code33'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12533"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p125code33"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Testt
  define_method <span style="color:#ff3333; font-weight:bold;">:foo</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#996600;">&quot;welcome&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
Testt.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">foo</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> welcome
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> Hello
  define_method <span style="color:#ff3333; font-weight:bold;">:foo</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>name<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#996600;">&quot;welcome #{name}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">include</span> Hello
foo <span style="color:#996600;">&quot;Dave&quot;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> welcome Dave</pre></td></tr></table></div>

<p>Now we can spice our project with metaprogramming. See how?<br />
Suppose in our project we had a model to maintain users</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code34'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12534"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p125code34"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#008000; font-style:italic;">#user has one role so association is</span>
  has_one <span style="color:#ff3333; font-weight:bold;">:role</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>We also have a Role model that belongs to user. Schema for role is suppose</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code35'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12535"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p125code35"><pre class="ruby" style="font-family:monospace;">Role<span style="color:#006600; font-weight:bold;">&#40;</span>id: <span style="color:#CC0066; font-weight:bold;">integer</span>, name: <span style="color:#CC0066; font-weight:bold;">string</span>, user_id: <span style="color:#CC0066; font-weight:bold;">integer</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>At the initiation of project the role known were admin and user. So I have defined two method in User model named as is_admin? and is_user?. But after some time we need to add some other roles as we need to define same function for them as well.</p>
<p>So to get rid of this we flavoured our project with bits of metaprogramming. See here how</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p125code36'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p12536"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p125code36"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#008000; font-style:italic;">#user has one role so association is</span>
  has_one <span style="color:#ff3333; font-weight:bold;">:role</span>
  <span style="color:#008000; font-style:italic;">#First time when there is no method found; this method will catch that</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">method_missing</span><span style="color:#006600; font-weight:bold;">&#40;</span>method_sym, <span style="color:#006600; font-weight:bold;">*</span>params<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#008000; font-style:italic;">#Here we match the pattern of method and see if we can process it or not</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> method_sym.<span style="color:#9900CC;">to_s</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^is_<span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>\?$<span style="color:#006600; font-weight:bold;">/</span>
      function = $1
&nbsp;
      class_eval <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span><span style="color:#9966CC; font-weight:bold;">END</span>
	<span style="color:#9966CC; font-weight:bold;">def</span> method_sym.<span style="color:#9900CC;">to_s</span>
	  <span style="color:#996600;">&quot;#{role.name == function.to_s.upcase}&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">END</span>
      <span style="color:#008000; font-style:italic;">#Let's register this method with user class when it is invoked first time.</span>
	send<span style="color:#006600; font-weight:bold;">&#40;</span>method_sym<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#9966CC; font-weight:bold;">super</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;">#Let this class respond for these methods</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>method_sym, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>amp;block<span style="color:#006600; font-weight:bold;">&#41;</span>
    method_sym.<span style="color:#9900CC;">to_s</span> =~ <span style="color:#006600; font-weight:bold;">/</span>^is_<span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>\?$<span style="color:#006600; font-weight:bold;">/</span> ? <span style="color:#0000FF; font-weight:bold;">true</span> : <span style="color:#9966CC; font-weight:bold;">super</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/gRGw8muFGSY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2010/04/metaprogramming-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2010/04/metaprogramming-in-rails/</feedburner:origLink></item>
		<item>
		<title>Action Mailer Configuration for Google app or Gmail</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/fumuCwlu6mA/</link>
		<comments>http://blog.railsjaipur.in/2009/12/using-gmail-with-rails/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 18:03:54 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[ActionMailer]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://blog.railsjaipur.in/?p=113</guid>
		<description><![CDATA[Recently I needed to setup smtp server to send mail. nothing was new, I simply used rails ActionMailer as one
should be. It should have been working, but wait; ohhhhhh snap, it was not!
It came out to be our very own google&#8217;s fault. Yes! as the email server was hosted on google app. And our google [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to setup smtp server to send mail. nothing was new, I simply used rails ActionMailer as one<br />
should be. It should have been working, but wait; ohhhhhh snap, it was not!</p>
<p>It came out to be our very own google&#8217;s fault. Yes! as the email server was hosted on google app. And our google uses SSL SMTP or to be precise STARTTLS for routing emails. So here I am writing down step by step, what worked for me.</p>
<p>1.  Create  #{RAILS_ROOT}/config/mailer_settings.yml with following code</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p113code41'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11341"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p113code41"><pre class="yaml" style="font-family:monospace;">development:
	enable_starttls_auto:  true
	address: &quot;smtp.gmail.com&quot;
	port: 587
	domain:  'http://'
	authentication: plain
	user_name: &quot;user@domain_name&quot;
	password:  your-password
&nbsp;
production:
	enable_starttls_auto:  true
	address: &quot;smtp.gmail.com&quot;
	port: 587
	domain:  'http://'
	authentication: plain
	user_name: &quot;user@domain_name&quot;
	password: your-password</pre></td></tr></table></div>

<p><strong>Note:</strong> you can use <em>enable_starttls_auto</em> directly if your rails version &gt; 2.2 and ruby<br />
version is &gt;=1.8.7, because built-in support for starttls. If not, then also you can use it; but you first need to install <a href="http://github.com/ambethia/smtp-tls">this gem</a>.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p113code42'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11342"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p113code42"><pre class="ruby" style="font-family:monospace;">gem install ambethia<span style="color:#006600; font-weight:bold;">-</span>smtp<span style="color:#006600; font-weight:bold;">-</span>tls</pre></td></tr></table></div>

<p>make dependencies</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p113code43'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11343"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p113code43"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#in &quot;#{RAILS_ROOT}/config/environment.rb&quot; write the following</span>
config.<span style="color:#9900CC;">gem</span> <span style="color:#996600;">&quot;ambethia-smtp-tls&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:lib</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;smtp-tls&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:source</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;http://gems.github.com/&quot;</span></pre></td></tr></table></div>

<p>2. Load mail configuration settings, if not in test environment</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p113code44'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p11344"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p113code44"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Load mail configuration if not in test environment</span>
<span style="color:#9966CC; font-weight:bold;">if</span> RAILS_ENV != <span style="color:#996600;">'test'</span>
	email_settings = <span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/config/mailer_settings.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span>.<span style="color:#9900CC;">smtp_settings</span> = email_settings<span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ENV<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> email_settings<span style="color:#006600; font-weight:bold;">&#91;</span>RAILS_ENV<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p> <img src='http://blog.railsjaipur.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Happy Boarding</p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/fumuCwlu6mA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2009/12/using-gmail-with-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2009/12/using-gmail-with-rails/</feedburner:origLink></item>
		<item>
		<title>Webrat Steps extension (Be more DRY)</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/hi3j_xm4oj0/</link>
		<comments>http://blog.railsjaipur.in/2009/12/webrat-steps-extensions/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 10:40:29 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Webrat]]></category>

		<guid isPermaLink="false">http://blog.railsjaipur.in/?p=64</guid>
		<description><![CDATA[Recently when I was working with Cucumber and Webrat, I found default webrat definition very interesting. Even in some case I didn&#8217;t even had to write a single step definition. But while proceeding I found that something is missing from webrat definition. So I decided to extend it. And come up with some methods defined [...]]]></description>
			<content:encoded><![CDATA[<p>Recently when I was working with Cucumber and Webrat, I found default webrat definition very interesting. Even in some case I didn&#8217;t even had to write a single step definition. But while proceeding I found that something is missing from webrat definition. So I decided to extend it. And come up with some methods defined as below.</p>
<p>To use them just download <a href="http://blog.railsjaipur.in/downloads/webrat_steps_extension.rb">this file</a> and put it under features/step_definitions/</p>
<p>You can copy below code clipboard</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p64code46'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6446"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
</pre></td><td class="code" id="p64code46"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#Created By Bagwan Pankaj (RailsJaipur) “http://railsjaipur.in/”</span>
<span style="color:#008000; font-style:italic;">#This file is an extension of default webrat steps. some of the webrat steps have been extended</span>
<span style="color:#008000; font-style:italic;">#in this file so that one need not to write unrequired steps.</span>
<span style="color:#008000; font-style:italic;">#Extends default</span>
<span style="color:#008000; font-style:italic;">#USE: When I follow //</span>
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I follow \<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>\<span style="color:#006600; font-weight:bold;">/</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>regexp_link<span style="color:#006600; font-weight:bold;">|</span>
  click_link<span style="color:#006600; font-weight:bold;">&#40;</span>regexp_link<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: When I follow // within &quot;&quot;</span>
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I follow \<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>\<span style="color:#006600; font-weight:bold;">/</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>regexp_link, parent<span style="color:#006600; font-weight:bold;">|</span>
  click_link_within<span style="color:#006600; font-weight:bold;">&#40;</span>parent,regexp_link<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: Then It should not include tag &quot;&quot;</span>
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^It should <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#9966CC; font-weight:bold;">include</span> tag <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag<span style="color:#006600; font-weight:bold;">|</span>
  assert_have_no_selector<span style="color:#006600; font-weight:bold;">&#40;</span>tag, <span style="color:#ff3333; font-weight:bold;">:count</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; 0<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: Then It should not include tag &quot;&quot; within &quot;&quot;</span>
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^It should <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#9966CC; font-weight:bold;">include</span> tag <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag_match, parent<span style="color:#006600; font-weight:bold;">|</span>
  within parent <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
    scope.<span style="color:#9900CC;">should_not</span> have_selector<span style="color:#006600; font-weight:bold;">&#40;</span>tag_match, <span style="color:#ff3333; font-weight:bold;">:count</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; 0<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: Then It should not include selector &quot;&quot;</span>
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^It should <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#9966CC; font-weight:bold;">include</span> selector <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>It should <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#9966CC; font-weight:bold;">include</span> tag \<span style="color:#996600;">&quot;#{tag}<span style="color:#000099;">\&quot;</span>}
end
&nbsp;
#USE: Then It should not include selector &quot;</span><span style="color:#996600;">&quot; within &quot;</span><span style="color:#996600;">&quot;
Then /^It should not include selector &quot;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#996600;">&quot;]*)&quot;</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag_match, parent<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>It should <span style="color:#9966CC; font-weight:bold;">not</span> <span style="color:#9966CC; font-weight:bold;">include</span> tag \<span style="color:#996600;">&quot;#{tag_match}<span style="color:#000099;">\&quot;</span> within <span style="color:#000099;">\&quot;</span>#{parent.to_s}<span style="color:#000099;">\&quot;</span>}
end
&nbsp;
#USE: Then It should include tag &quot;</span><span style="color:#996600;">&quot;
Then /^It should include tag &quot;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#996600;">&quot;]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag<span style="color:#006600; font-weight:bold;">|</span>
  assert_have_selector<span style="color:#006600; font-weight:bold;">&#40;</span>tag<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: Then It should include tag &quot;&quot; within &quot;&quot;</span>
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^It should <span style="color:#9966CC; font-weight:bold;">include</span> tag <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag_match, parent<span style="color:#006600; font-weight:bold;">|</span>
  within parent <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
    scope.<span style="color:#9900CC;">should</span> have_selector<span style="color:#006600; font-weight:bold;">&#40;</span>tag_match<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: Then It should include selector &quot;&quot;</span>
<span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">/</span>^It should <span style="color:#9966CC; font-weight:bold;">include</span> selector <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>It should <span style="color:#9966CC; font-weight:bold;">include</span> tag \<span style="color:#996600;">&quot;#{tag}<span style="color:#000099;">\&quot;</span>}
end
&nbsp;
#USE: Then It should include selector &quot;</span><span style="color:#996600;">&quot; within &quot;</span><span style="color:#996600;">&quot;
Then /^It should include selector &quot;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#996600;">&quot;]*)&quot;</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>tag_match, parent<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">Then</span> <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span>It should <span style="color:#9966CC; font-weight:bold;">include</span> tag \<span style="color:#996600;">&quot;#{tag_match}<span style="color:#000099;">\&quot;</span> within <span style="color:#000099;">\&quot;</span>#{parent.to_s}<span style="color:#000099;">\&quot;</span>}
end
&nbsp;
#USE: When I check // within “”
When /^I check <span style="color:#000099;">\/</span>([^<span style="color:#000099;">\/</span>]*)<span style="color:#000099;">\/</span> within &quot;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#996600;">&quot;]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>field, parent<span style="color:#006600; font-weight:bold;">|</span>
  within parent <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
    regexp = <span style="color:#CC00FF; font-weight:bold;">Regexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#41;</span>
    scope.<span style="color:#9900CC;">check</span><span style="color:#006600; font-weight:bold;">&#40;</span>regexp<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: When /^I check “([^\&quot;]*)” within “”</span>
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^I check <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>field, parent<span style="color:#006600; font-weight:bold;">|</span>
  within parent <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
    scope.<span style="color:#9900CC;">check</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: When /^(?:|I )check //</span>
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">|</span>I <span style="color:#006600; font-weight:bold;">&#41;</span>check \<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>\<span style="color:#006600; font-weight:bold;">/</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>field<span style="color:#006600; font-weight:bold;">|</span>
  regexp = <span style="color:#CC00FF; font-weight:bold;">Regexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#41;</span>
  check<span style="color:#006600; font-weight:bold;">&#40;</span>regexp<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: I should be able to see  &quot;</span>
<span style="color:#996600;">&quot;
Then /^I should be able to see (<span style="color:#000099;">\d</span>+) &quot;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#996600;">&quot;]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>count,selector<span style="color:#006600; font-weight:bold;">|</span>
  assert_have_selector<span style="color:#006600; font-weight:bold;">&#40;</span>selector, <span style="color:#ff3333; font-weight:bold;">:count</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; count<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#USE: I should be able to see  &quot;</span>
<span style="color:#996600;">&quot; within &quot;</span>
<span style="color:#996600;">&quot;
Then /^I should be able to see (<span style="color:#000099;">\d</span>+) &quot;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#996600;">&quot;]*)&quot;</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>count,selector, parent<span style="color:#006600; font-weight:bold;">|</span>
  within parent <span style="color:#9966CC; font-weight:bold;">do</span>  <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
    scope.<span style="color:#9900CC;">should</span> have_selector<span style="color:#006600; font-weight:bold;">&#40;</span>selector, <span style="color:#ff3333; font-weight:bold;">:count</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; count<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">|</span>I <span style="color:#006600; font-weight:bold;">&#41;</span>choose <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>field,parent<span style="color:#006600; font-weight:bold;">|</span>
  within parent <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
    scope.<span style="color:#9900CC;">choose</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">When</span> <span style="color:#006600; font-weight:bold;">/</span>^<span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">|</span>I <span style="color:#006600; font-weight:bold;">&#41;</span>choose \<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>\<span style="color:#006600; font-weight:bold;">/</span> within <span style="color:#996600;">&quot;([^<span style="color:#000099;">\&quot;</span>]*)&quot;</span>$<span style="color:#006600; font-weight:bold;">/</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>field,parent<span style="color:#006600; font-weight:bold;">|</span>
  within parent <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
    regexp = <span style="color:#CC00FF; font-weight:bold;">Regexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>field<span style="color:#006600; font-weight:bold;">&#41;</span>
    scope.<span style="color:#9900CC;">choose</span><span style="color:#006600; font-weight:bold;">&#40;</span>regexp<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now you can use above listed methods easily and I assure you that if you use them properly you do not have to write a single step definition.</p>
<p>Their uses can be found against USE in the downloaded file.</p>
<p><em>&#8220;Use the Rails the way Rails is&#8221;</em></p>
<p><em>Happy Boarding <img src='http://blog.railsjaipur.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
</em></p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/hi3j_xm4oj0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2009/12/webrat-steps-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2009/12/webrat-steps-extensions/</feedburner:origLink></item>
		<item>
		<title>Cucumber + Webrat CheatSheet</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/LdU8hkWnXD0/</link>
		<comments>http://blog.railsjaipur.in/2009/11/cucumber-webrat-cheatsheet/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 13:08:05 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.railsjaipur.in/?p=59</guid>
		<description><![CDATA[Webrat &#8211; Ruby Acceptance Testing for Web applications
Download PDF format
Before starting here are some useful links
	http://gitrdoc.com/brynary/webrat
	http://groups.google.com/group/webrat
	http://webrat.lighthouseapp.com/
	http://github.com/brynary/webrat
	#webrat on Freenode
Simulating browser events
1. Visiting a URL

GET a URL, following any redirects, and making sure final page is successful

?View Code RUBY1
visit &#34;/some/url&#34;


In general, elements can be located by their inner text, their &#8216;title&#8217; attribute, their &#8216;name&#8217; attribute, and their [...]]]></description>
			<content:encoded><![CDATA[<h3>Webrat &#8211; Ruby Acceptance Testing for Web applications</h3>
<p><a href="http://blog.railsjaipur.in/downloads/CheatSheet_Webrat.pdf">Download PDF format</a></p>
<p><strong>Before starting here are some useful links</strong></p>
<pre>	http://gitrdoc.com/brynary/webrat
	http://groups.google.com/group/webrat
	http://webrat.lighthouseapp.com/
	http://github.com/brynary/webrat
	#webrat on Freenode</pre>
<h4>Simulating browser events</h4>
<p><strong>1. Visiting a URL<br />
</strong></p>
<p>GET a URL, following any redirects, and making sure final page is successful</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code61'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5961"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p59code61"><pre class="ruby" style="font-family:monospace;">visit <span style="color:#996600;">&quot;/some/url&quot;</span></pre></td></tr></table></div>

<ul>
<li>In general, elements can be located by their inner text, their &#8216;title&#8217; attribute, their &#8216;name&#8217; attribute, and their &#8216;id&#8217; attribute.</li>
<li>They can be selected using a String, which is converted to an escaped Regexp effectively making it a substring match, or using a Regexp.</li>
<li>An exception is that using Strings for ids are compared exactly (using ==) rather than converted to a Regexp</li>
<li>If the element you are trying to look up does not exist, an error occurs</li>
</ul>
<p><strong>2. Visiting Link</strong></p>
<p>Links can be looked up by text, title, or id</p>
<p>for example To match&#8230; <a id="signup_link" title="Sign up" href="#">Click here to join!</a></p>
<p>we can write down like</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code62'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5962"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p59code62"><pre class="ruby" style="font-family:monospace;">click_link <span style="color:#996600;">&quot;Click here to join!&quot;</span>             <span style="color:#008000; font-style:italic;"># substring text</span>
click_link <span style="color:#006600; font-weight:bold;">/</span>join<span style="color:#006600; font-weight:bold;">/</span>i                                    <span style="color:#008000; font-style:italic;"># regexp text</span>
click_link <span style="color:#996600;">&quot;Sign up&quot;</span>                             <span style="color:#008000; font-style:italic;"># substring title</span>
click_link <span style="color:#006600; font-weight:bold;">/</span>sign.<span style="color:#006600; font-weight:bold;">*</span>up<span style="color:#006600; font-weight:bold;">/</span>i                            <span style="color:#008000; font-style:italic;"># regexp title</span>
click_link <span style="color:#006600; font-weight:bold;">/</span>signup.<span style="color:#006600; font-weight:bold;">*</span>link<span style="color:#006600; font-weight:bold;">/</span>i                       <span style="color:#008000; font-style:italic;"># regexp id</span>
click_link <span style="color:#996600;">&quot;signup_link&quot;</span>                       <span style="color:#008000; font-style:italic;"># exact id</span></pre></td></tr></table></div>

<p><strong>3. Filling Up a form</strong></p>
<p>Note:</p>
<ul>
<li>All fields can be looked up by ID, name, or label inner text</li>
<li>Text fields, password fields, and text areas can be filled in using <em>fill_in</em></li>
</ul>
<p><label for="user[email]">Enter your Email</label></p>
<input id="user_name" name="user[email]" type="text" />

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code63'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5963"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p59code63"><pre class="ruby" style="font-family:monospace;">fill_in <span style="color:#996600;">&quot;user_email&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:with</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;test@example.com&quot;</span>                     <span style="color:#008000; font-style:italic;"># exact id</span>
fill_in <span style="color:#006600; font-weight:bold;">/</span>user.<span style="color:#006600; font-weight:bold;">*</span>email<span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#ff3333; font-weight:bold;">:with</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;test@example.com&quot;</span>                   <span style="color:#008000; font-style:italic;"># regexp id</span>
fill_in <span style="color:#996600;">&quot;user[email]&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:with</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;test@example.com&quot;</span>               <span style="color:#008000; font-style:italic;"># substring name</span>
fill_in <span style="color:#006600; font-weight:bold;">/</span>user<span style="color:#006600; font-weight:bold;">&#91;</span>.<span style="color:#006600; font-weight:bold;">*</span>mail.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">/</span>, <span style="color:#ff3333; font-weight:bold;">:with</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;test@example.com&quot;</span>          <span style="color:#008000; font-style:italic;"># substring name</span>
fill_in <span style="color:#996600;">&quot;&lt;label for=&quot;</span>user<span style="color:#006600; font-weight:bold;">&#91;</span>email<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#996600;">&quot;&gt;Enter your Email&lt;/label&gt;&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:with</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;test@example.com&quot;</span>    <span style="color:#008000; font-style:italic;"># substring label text</span>
fill_in <span style="color:#006600; font-weight:bold;">/</span>enter your email<span style="color:#006600; font-weight:bold;">/</span>i, <span style="color:#ff3333; font-weight:bold;">:with</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;test@example.com&quot;</span>    <span style="color:#008000; font-style:italic;"># regexp label text</span></pre></td></tr></table></div>

<p>Note: Hidden fields can also be set using</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code64'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5964"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p59code64"><pre class="ruby" style="font-family:monospace;">set_hidden_field <span style="color:#996600;">'user[l337_test]'</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">'true'</span></pre></td></tr></table></div>

<p><strong>4. Selecting from Drop Down</strong></p>
<p>Select options can be &#8217;selected&#8217; by inner text (an exact String or a Regexp to match). It can optionally be selected from a particular select field, using<br />
the usual id, name, or label text.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code65'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5965"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p59code65"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#996600;">&quot;Free account&quot;</span>
<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#996600;">&quot;Free account&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:from</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;Account Types&quot;</span>
<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#996600;">&quot;Free account&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:from</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;user[account_type]&quot;</span>
<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#996600;">&quot;Free account&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:from</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; <span style="color:#996600;">&quot;user_account_type&quot;</span></pre></td></tr></table></div>

<p><strong>5. Check Boxes</strong></p>
<p>Check boxes can be &#8216;checked&#8217; and &#8216;unchecked&#8217;</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code66'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5966"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p59code66"><pre class="ruby" style="font-family:monospace;">check <span style="color:#996600;">'Remember me'</span>
uncheck <span style="color:#996600;">'Remember me'</span></pre></td></tr></table></div>

<p><strong>6. Radio Buttons</strong></p>
<p>Radio buttons can be also choosen, using the usual label text, name, or id.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code67'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5967"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p59code67"><pre class="ruby" style="font-family:monospace;">choose <span style="color:#996600;">&quot;Yes&quot;</span></pre></td></tr></table></div>

<p><strong>7. Buttons</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code68'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5968"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p59code68"><pre class="ruby" style="font-family:monospace;">click_button <span style="color:#996600;">&quot;Register&quot;</span></pre></td></tr></table></div>

<p><strong>Assertions</strong></p>
<p>check for text in the body of html tags<br />
can be a string or regexp</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code69'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5969"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p59code69"><pre class="ruby" style="font-family:monospace;">assert_contain<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Successfully created&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
assert_contain<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>trogdor<span style="color:#006600; font-weight:bold;">/</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
assert_not_contain<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;peasants&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>check for a css3 selector</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code70'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5970"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p59code70"><pre class="ruby" style="font-family:monospace;">assert_have_selector <span style="color:#996600;">'div.pagination'</span>
assert_have_no_selector <span style="color:#996600;">'form input#name'</span></pre></td></tr></table></div>

<p>Note: Assertion does work not inside block</p>
<p><strong>Matchers</strong></p>
<p>check for text in the body of html tags<br />
an be a string or regexp</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code71'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5971"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p59code71"><pre class="ruby" style="font-family:monospace;">response.<span style="color:#9900CC;">should</span> contain<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;BURNINATOR&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
response.<span style="color:#9900CC;">should</span> contain<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>trogdor<span style="color:#006600; font-weight:bold;">/</span>i<span style="color:#006600; font-weight:bold;">&#41;</span>
response.<span style="color:#9900CC;">should_not</span> contain<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;peasants&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>check for a css3 selector</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code72'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5972"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p59code72"><pre class="ruby" style="font-family:monospace;">response.<span style="color:#9900CC;">should</span> have_selector<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'div.pagination'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
response.<span style="color:#9900CC;">should_not</span> have_selector<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'form input#name'</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p><strong>Targetted actions/matchers</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code73'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5973"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p59code73"><pre class="ruby" style="font-family:monospace;">within <span style="color:#996600;">'div.pagination'</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
	scope.<span style="color:#9900CC;">click_link</span> <span style="color:#996600;">&quot;1&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p59code74'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p5974"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p59code74"><pre class="ruby" style="font-family:monospace;">within <span style="color:#996600;">'.shows'</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>scope<span style="color:#006600; font-weight:bold;">|</span>
	scope.<span style="color:#9900CC;">should</span> contain<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;NFL&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#008000; font-style:italic;"># unfortunately, assertions don't support this currently</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/LdU8hkWnXD0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2009/11/cucumber-webrat-cheatsheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2009/11/cucumber-webrat-cheatsheet/</feedburner:origLink></item>
		<item>
		<title>SCRUM methodology</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/wAEpIyb9jdg/</link>
		<comments>http://blog.railsjaipur.in/2009/10/scrum-methodology/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 09:48:47 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[SCRUM]]></category>
		<category><![CDATA[Agile software-lifecycle SCRUM]]></category>

		<guid isPermaLink="false">http://railsjaipur.wordpress.com/?p=53</guid>
		<description><![CDATA[Rails is agile.
Ummmmmmm&#8230;&#8230;&#8230;. Am I right??
Agile is awesome n so is SCRUM
Confused????
There are three agile software development methodology out there.
first the XP(Extreme Programming), Second Crystal Clear and third one is SCRUM. SCRUM is what that fascinates me.
SCRUM is all about developing a software in an incremental iterative  framework. In SCRUM we provide our client [...]]]></description>
			<content:encoded><![CDATA[<p>Rails is agile.<br />
Ummmmmmm&#8230;&#8230;&#8230;. Am I right??<br />
Agile is awesome n so is SCRUM<br />
Confused????</p>
<p>There are three agile software development methodology out there.<br />
first the XP(Extreme Programming), Second Crystal Clear and third one is SCRUM. SCRUM is what that fascinates me.</p>
<p>SCRUM is all about developing a software in an incremental iterative  framework. In SCRUM we provide our client a single running module of project in an certain timeline (generally 2 to 4 week) called Sprint.</p>
<div id="attachment_52" class="wp-caption aligncenter" style="width: 490px"><img class="size-full wp-image-52" title="800px-Scrum_process.svg" src="http://railsjaipur.files.wordpress.com/2009/10/800px-scrum_process-svg.png" alt="SCRUM" width="480" height="240" /><p class="wp-caption-text">SCRUM</p></div>
<p>In scrum, there are three roles.<br />
1. Product Owner (or client)</p>
<p>The role of Product owner is to just Prioritize the requirement that he/she/they wanted to be developed within a limited timespan.</p>
<p>2. ScrumMaster</p>
<p>The role of ScrumMaster  (or Project Manager) is to prioritize the product backlog (given by Product Owner) and Lead the Scrum meeting (Probably in every 24 hour). Requirements are frozen once they are in sprint backlog. No one allowed to change them even Product Owner.</p>
<p>3. The Team</p>
<p>The team of 5-10 people specializes in cross functional skills (Design, develop,test.. etc.) who does the actual work (build a shippable item in a sprint)</p>
<p>That&#8217;s really it.</p>
<p> <img src='http://blog.railsjaipur.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/wAEpIyb9jdg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2009/10/scrum-methodology/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2009/10/scrum-methodology/</feedburner:origLink></item>
		<item>
		<title>What is Rake</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/ZX0oAgXkmIo/</link>
		<comments>http://blog.railsjaipur.in/2009/10/what-is-rake/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 16:26:25 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://railsjaipur.wordpress.com/?p=49</guid>
		<description><![CDATA[In Ruby Rake is a software build tool similar to linux&#8217;s make, Apache&#8217;s Ant.
It is Written and use ruby Language.
In rake you can define dependencies of one rake task on other pre written
tasks.
When we run the rake command it looks for a rakefile to load the rake task for predefined or default rake tasks then [...]]]></description>
			<content:encoded><![CDATA[<p>In Ruby Rake is a software build tool similar to linux&#8217;s make, Apache&#8217;s Ant.<br />
It is Written and use ruby Language.</p>
<p>In rake you can define dependencies of one rake task on other pre written<br />
tasks.</p>
<p>When we run the rake command it looks for a rakefile to load the rake task for predefined or default rake tasks then it loads rake task passed to it as a parameter.</p>
<p>If one don&#8217;t pass it parameters then it lists all the defined rake task.</p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/ZX0oAgXkmIo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2009/10/what-is-rake/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2009/10/what-is-rake/</feedburner:origLink></item>
		<item>
		<title>Difference Between Gem and Plugin</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/zoKg1Grl6pA/</link>
		<comments>http://blog.railsjaipur.in/2009/10/difference-between-gem-and-plugin/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 16:10:51 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://railsjaipur.wordpress.com/?p=47</guid>
		<description><![CDATA[Now a days many developers are developing web application using ruby on rails. But a few of them know what actually the difference between &#8220;Gem&#8221; and &#8220;Plugin&#8221;.
Here are some of them
GEM
1. Gem is a packaged ruby application using the packaging system defined by RubyGems.
2. Rails itself is a Gem
3. We can install,upgrade and query the [...]]]></description>
			<content:encoded><![CDATA[<p>Now a days many developers are developing web application using ruby on rails. But a few of them know what actually the difference between &#8220;Gem&#8221; and &#8220;Plugin&#8221;.</p>
<p>Here are some of them<br />
<strong>GEM</strong><br />
1. Gem is a packaged ruby application using the packaging system defined by RubyGems.<br />
2. Rails itself is a Gem<br />
3. We can install,upgrade and query the gem version.<br />
4. Gem installed for Ruby interpreter can be used system-wide by that interpreter.</p>
<p><strong>Plugin</strong></p>
<p>1. Plugin is an extension of Rails Framework.<br />
2. Can not be upgraded by using a command. To upgrade one have to uninstall and then install upgraded version.<br />
3. Has to be hooked into rails application. (has to have init.rb)<br />
4. Have an install.rb file.<br />
5. Can only be used application wide.</p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/zoKg1Grl6pA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2009/10/difference-between-gem-and-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2009/10/difference-between-gem-and-plugin/</feedburner:origLink></item>
		<item>
		<title>Working with namepaced model</title>
		<link>http://feedproxy.google.com/~r/RailsPlayground/~3/Td3AGBwwRLs/</link>
		<comments>http://blog.railsjaipur.in/2009/10/working-with-namepaced-model/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 14:50:15 +0000</pubDate>
		<dc:creator>Bagwan Pankaj</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[activaeRecord]]></category>
		<category><![CDATA[I18n]]></category>
		<category><![CDATA[namespaced]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://railsjaipur.wordpress.com/?p=44</guid>
		<description><![CDATA[Sometime we have to work with namespaced model in Ruby on Rails to keep our code clean.
For example:
I have model named as &#8220;Attandance.rb&#8221;,
Sometime to keep our code clean we have to put them in custom dir.
This scenario is normal while working with two or three modules.
for ex. I have three module in a project for [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime we have to work with namespaced model in Ruby on Rails to keep our code clean.<br />
For example:<br />
I have model named as &#8220;Attandance.rb&#8221;,<br />
Sometime to keep our code clean we have to put them in custom dir.<br />
This scenario is normal while working with two or three modules.<br />
for ex. I have three module in a project for school.<br />
1. Admin module, Teachers module and a Student module.</p>
<p>So it is better to put all stuff that belongs to teacher in a custom dir named &#8220;Teachers&#8221;</p>
<p>Be sure that folder name does not match any model that have been put under this folder. I prefer to use plural names for these directories.</p>
<p>But now begins the real headache.<br />
to access model under the &#8220;Teachers&#8221; directory I have to write this</p>
<p>Teachers::Attendance.find and all that.<br />
And for sure it will be a headache while translating with I18n.</p>
<p>But this violates Ruby&#8217;s very own DRY approach.</p>
<p>So to keep being DRY do the below written things.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p44code77'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4477"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p44code77"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#Open config/environment.rb file.</span>
<span style="color:#008000; font-style:italic;">#Write</span>
config.<span style="color:#9900CC;">load_paths</span> <span style="color:#006600; font-weight:bold;">+</span>= <span style="color:#006600; font-weight:bold;">%</span>W<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#008000; font-style:italic;">#{RAILS_ROOT}/app/models/teachers,</span>
                        <span style="color:#008000; font-style:italic;">#{RAILS_ROOT}/app/models/ur_custom_dir)</span></pre></td></tr></table></div>

<p>And you are done.<br />
now you can have access to these model like others<br />
Attendance.find()<br />
and while translating you can write normally as you do whith other models.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p44code78'); return false;">View Code</a> YAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4478"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p44code78"><pre class="yaml" style="font-family:monospace;">hi:
  activerecord:
    attributes:
      attendance:
        teacher_id: “xE0\xA4\x97?
        name: ” \xE0\xA4\x94\xE0\xA4\xB0 “</pre></td></tr></table></div>

<p>Don&#8217;t go on Unicode they are not real.</p>
<p>This is a little thing but it solves many problem that can come in your way.</p>
<p>Happy boarding.</p>
<img src="http://feeds.feedburner.com/~r/RailsPlayground/~4/Td3AGBwwRLs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.railsjaipur.in/2009/10/working-with-namepaced-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.railsjaipur.in/2009/10/working-with-namepaced-model/</feedburner:origLink></item>
	</channel>
</rss>
