<?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>DevInterface Blog</title>
	
	<link>http://blog.devinterface.com</link>
	<description>Information Technology Professionals</description>
	<lastBuildDate>Thu, 26 Jan 2012 19:52:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</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/devinterfaceblog" /><feedburner:info uri="devinterfaceblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>devinterfaceblog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>How to insert more Disqus comments box in a single page</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/gX0IBD4q8PM/</link>
		<comments>http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 19:52:17 +0000</pubDate>
		<dc:creator>Claudio</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[disqus]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[jqeury]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1132</guid>
		<description><![CDATA[Hello everyone!

For those not familiar Disqus is a platform that allows you to easily insert a box for comments on any website and allows users to use the their Facebook or Twitter account (but not only) to authenticate.


The limit of  Disqus is that it associates any thread of  comments to a unique url.
Consequently, [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone!</p>
<p>
For those not familiar <a href="http://disqus.com/">Disqus</a> is a platform that allows you to easily insert a box for comments on any website and allows users to use the their Facebook or Twitter account (but not only) to authenticate.
</p>
<p>
The limit of  Disqus is that it associates any thread of  comments to a unique url.<br />
Consequently, it will expect that in every page there is only a comment box.
</p>
<p>
In most cases this limit is acceptable, but for some applications it is useful to put more comments boxes on a single page. As an example think about a blog where you want to give the opportunity to comment on each post directly from the main page which lists all the posts one under each other.
</p>
<p>
What I want to show you today is a method to overcome the limit of Disqus and easily implement a page with more <strong>comments boxes</strong>, as in the blog example.<br />
Using an <strong>iframe</strong> and <strong>jQuery</strong> we will make the boxes also dynamically loaded.</p>
<p>
Suppose that we have our page index.html.haml as follows and to already have a Disqus account:
</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">-</span> <span style="color:#0066ff; font-weight:bold;">@posts</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>post<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; = show_for post <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; = s.<span style="color:#9900CC;">attribute</span> <span style="color:#ff3333; font-weight:bold;">:title</span><br />
&nbsp; &nbsp; = s.<span style="color:#9900CC;">attribute</span> <span style="color:#ff3333; font-weight:bold;">:body</span></div></td></tr></tbody></table></div>
<p>
The idea is to create an iframe dynamically below each post and have it displayed / hidden by jQuery when you click on a link &#8220;comments&#8221;.</p>
<p>We start creating the page comments.html.haml that we want to load inside the iframe.
</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#disqus_thread</span><br />
<br />
<span style="color:#006600; font-weight:bold;">%</span>noscript<br />
&nbsp; Please enable JavaScript to view the<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>a<span style="color:#006600; font-weight:bold;">&#123;</span>:href <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://disqus.com/?ref_noscript&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> comments powered by Disqus.<br />
<br />
<span style="color:#006600; font-weight:bold;">%</span>a.<span style="color:#9900CC;">dsq</span><span style="color:#006600; font-weight:bold;">-</span>brlink<span style="color:#006600; font-weight:bold;">&#123;</span>:href <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;http://disqus.com&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; blog comments powered by<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>span.<span style="color:#9900CC;">logo</span><span style="color:#006600; font-weight:bold;">-</span>disqus Disqus<br />
<br />
<br />
<span style="color:#ff3333; font-weight:bold;">:javascript</span><br />
&nbsp; var disqus_shortname = <span style="color:#996600;">'devinterface-example'</span>;<br />
<br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>function<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;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; var dsq = document.<span style="color:#9900CC;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'script'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; dsq.<span style="color:#9900CC;">type</span> = <span style="color:#996600;">'text/javascript'</span>; dsq.<span style="color:#9900CC;">async</span> = <span style="color:#0000FF; font-weight:bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; dsq.<span style="color:#9900CC;">src</span> = <span style="color:#996600;">'http://'</span> <span style="color:#006600; font-weight:bold;">+</span> disqus_shortname <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'.disqus.com/embed.js'</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>document.<span style="color:#9900CC;">getElementsByTagName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'head'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> document.<span style="color:#9900CC;">getElementsByTagName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'body'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>dsq<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; <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;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<br />
&nbsp; function disqus_config<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;">&#123;</span><br />
&nbsp; &nbsp; this.<span style="color:#9900CC;">callbacks</span>.<span style="color:#9900CC;">onReady</span> = <span style="color:#006600; font-weight:bold;">&#91;</span>function<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;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; var frameHeight = $<span style="color:#006600; font-weight:bold;">&#40;</span>document<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">height</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'iframe.comment_frame'</span>, top.<span style="color:#9900CC;">document</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;height&quot;</span>, frameHeight<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
&nbsp; &nbsp; this.<span style="color:#9900CC;">callbacks</span>.<span style="color:#9900CC;">onNewComment</span> = <span style="color:#006600; font-weight:bold;">&#91;</span>function<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;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; var frameHeight = $<span style="color:#006600; font-weight:bold;">&#40;</span>document<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">height</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'iframe.comment_frame'</span>, top.<span style="color:#9900CC;">document</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;height&quot;</span>, frameHeight<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span>;<br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>
On this page, we insert the html and javascript provided by Disqus and we set the variable <em><strong>disqus_shortname</strong></em>.<br />
Then, using the <em>disqus_config</strong></em> function we set two callbacks for Disqus so that after the complete loading or aftere a new  comment is inserted, the iframe that contains this page be appropriately resized<br />
NOTE: resizing iframe &#8220;container&#8221; is only possible because the two page &#8220;index&#8221; and &#8220;comments&#8221; are on the same domain. If not, in fact, access to the parent of an iframe would be impossible for the security policy of browsers.
</p>
<p>
Now that we have created our comments page, we have only to add the iframe dynamically to the index page.<br />
To make things more &#8220;cool&#8221; we use the count of comments for each post as the link that will open/close the comments box.
</p>
<p>
Now we return to the index page and modify it as follows:
</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">-</span> <span style="color:#0066ff; font-weight:bold;">@posts</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>post<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; = show_for post <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>s<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; = s.<span style="color:#9900CC;">attribute</span> <span style="color:#ff3333; font-weight:bold;">:title</span><br />
&nbsp; &nbsp; = s.<span style="color:#9900CC;">attribute</span> <span style="color:#ff3333; font-weight:bold;">:body</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">/</span> disqus comments<br />
&nbsp; &nbsp; = link_to <span style="color:#996600;">&quot;&quot;</span>, <span style="color:#996600;">&quot;/#{post.slug}/comments#disqus_thread&quot;</span>, :<span style="color:#9966CC; font-weight:bold;">class</span><span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;dq_comment&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> post.<span style="color:#9900CC;">id</span><br />
&nbsp; &nbsp; .<span style="color:#9900CC;">comment_box</span><span style="color:#006600; font-weight:bold;">&#123;</span>:id <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;comment_#{post.id}&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#ff3333; font-weight:bold;">:javascript</span><br />
&nbsp; var disqus_shortname = <span style="color:#996600;">'devinterface-example'</span>;<br />
<br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>function <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;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; var s = document.<span style="color:#9900CC;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'script'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; s.<span style="color:#9900CC;">async</span> = <span style="color:#0000FF; font-weight:bold;">true</span>;<br />
&nbsp; &nbsp; &nbsp; s.<span style="color:#9900CC;">type</span> = <span style="color:#996600;">'text/javascript'</span>;<br />
&nbsp; &nbsp; &nbsp; s.<span style="color:#9900CC;">src</span> = <span style="color:#996600;">'http://'</span> <span style="color:#006600; font-weight:bold;">+</span> disqus_shortname <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'.disqus.com/count.js'</span>;<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>document.<span style="color:#9900CC;">getElementsByTagName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'HEAD'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span> document.<span style="color:#9900CC;">getElementsByTagName</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'BODY'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>s<span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><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;">&#41;</span>;<br />
<br />
&nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span>document<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">ready</span><span style="color:#006600; font-weight:bold;">&#40;</span>function<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;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.dq_comment&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span><span style="color:#006600; font-weight:bold;">&#40;</span>function<span style="color:#006600; font-weight:bold;">&#40;</span>e<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color:#9900CC;">preventDefault</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; var id = $<span style="color:#006600; font-weight:bold;">&#40;</span>this<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;id&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; var href = $<span style="color:#006600; font-weight:bold;">&#40;</span>this<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;href&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; var src = href.<span style="color:#9900CC;">substring</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span>,href.<span style="color:#9900CC;">length</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">14</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#006600; font-weight:bold;">//</span> Remove <span style="color:#008000; font-style:italic;">#disqus_thread</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#comment_&quot;</span><span style="color:#006600; font-weight:bold;">+</span>id<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">is</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">':visible'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#comment_&quot;</span><span style="color:#006600; font-weight:bold;">+</span>id<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">html</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#comment_&quot;</span><span style="color:#006600; font-weight:bold;">+</span>id<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">append</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'&lt;iframe scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;'</span><span style="color:#006600; font-weight:bold;">+</span>src<span style="color:#006600; font-weight:bold;">+</span><span style="color:#996600;">'&quot; class=&quot;comment_frame&quot;&gt;&lt;/iframe&gt;'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#comment_&quot;</span><span style="color:#006600; font-weight:bold;">+</span>id<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">toggle</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'slow'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>
As you can see we have added the link with the unique url of the post and the tag <strong># disqus_thread</strong> to activate the counter of the comments, as explained in the <a href="http://docs.disqus.com/developers/Universal/ " rel="nofollow">documentation</a>.<br />
Finally, using the jQuery function we intercepted the click on the link in such a way to dynamically create an iframe below the post with the url of our comments.html.haml page.<br />
Obviously the comments page&#8217;s url have to be appropriately defined in our routes file.
</p>
<p>
Now you just need to open your browser and see your posts, each with its comments box dynamically loaded by clicking on the counter link.
</p>
<p>
NOTE: If you try these scripts on localhost, remember to add to the two Disqus javascript:
</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #003366; font-weight: bold;">var</span> disqus_developer <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>
just below disqus_shortname.
</p>
<p><!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'How to insert more Disqus comments box in a single page' to Del.icio.us" alt="Add 'How to insert more Disqus comments box in a single page' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'How to insert more Disqus comments box in a single page' to digg" alt="Add 'How to insert more Disqus comments box in a single page' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'How to insert more Disqus comments box in a single page' to reddit" alt="Add 'How to insert more Disqus comments box in a single page' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="Add 'How to insert more Disqus comments box in a single page' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'How to insert more Disqus comments box in a single page' to Technorati" alt="Add 'How to insert more Disqus comments box in a single page' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'How to insert more Disqus comments box in a single page' to Stumble Upon" alt="Add 'How to insert more Disqus comments box in a single page' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'How to insert more Disqus comments box in a single page' to Google Bookmarks" alt="Add 'How to insert more Disqus comments box in a single page' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="Add 'How to insert more Disqus comments box in a single page' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'How to insert more Disqus comments box in a single page' to Rojo" alt="Add 'How to insert more Disqus comments box in a single page' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'How to insert more Disqus comments box in a single page' to OKnotizie" alt="Add 'How to insert more Disqus comments box in a single page' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=How+to+insert+more+Disqus+comments+box+in+a+single+page&amp;url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="Add 'How to insert more Disqus comments box in a single page' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'How to insert more Disqus comments box in a single page' to Diggita" alt="Add 'How to insert more Disqus comments box in a single page' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;t=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'How to insert more Disqus comments box in a single page' to FaceBook" alt="Add 'How to insert more Disqus comments box in a single page' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page" title="Add 'How to insert more Disqus comments box in a single page' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'How to insert more Disqus comments box in a single page' to Upnews" alt="Add 'How to insert more Disqus comments box in a single page' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="Add 'How to insert more Disqus comments box in a single page' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'How to insert more Disqus comments box in a single page' to Twitter" alt="Add 'How to insert more Disqus comments box in a single page' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page&amp;url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="Add 'How to insert more Disqus comments box in a single page' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'How to insert more Disqus comments box in a single page' to Technotizie" alt="Add 'How to insert more Disqus comments box in a single page' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=How+to+insert+more+Disqus+comments+box+in+a+single+page&amp;url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="Add 'How to insert more Disqus comments box in a single page' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'How to insert more Disqus comments box in a single page' to FriendFeed" alt="Add 'How to insert more Disqus comments box in a single page' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/&amp;title=How+to+insert+more+Disqus+comments+box+in+a+single+page&amp;srcURL=http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="Add 'How to insert more Disqus comments box in a single page' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'How to insert more Disqus comments box in a single page' to Google Buzz" alt="Add 'How to insert more Disqus comments box in a single page' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="<!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:-->"><!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="<!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:-->"><!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="<!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:-->"><!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:--></a></li><li><a href="http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="<!--:en-->A new layout easier and more spacious<!--:--><!--:it-->Un nuovo layout più semplice e spazioso<!--:-->"><!--:en-->A new layout easier and more spacious<!--:--><!--:it-->Un nuovo layout più semplice e spazioso<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="<!--:en-->How to send email asynchronously using Devise and Rails3<!--:--><!--:it-->Come spedire email in modo asincrono con Devise e Rails3<!--:-->"><!--:en-->How to send email asynchronously using Devise and Rails3<!--:--><!--:it-->Come spedire email in modo asincrono con Devise e Rails3<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/JzTMJXWrdFilNHHk8xeWIpzVPFY/0/da"><img src="http://feedads.g.doubleclick.net/~a/JzTMJXWrdFilNHHk8xeWIpzVPFY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/JzTMJXWrdFilNHHk8xeWIpzVPFY/1/da"><img src="http://feedads.g.doubleclick.net/~a/JzTMJXWrdFilNHHk8xeWIpzVPFY/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=gX0IBD4q8PM:kiuJz3guxFQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=gX0IBD4q8PM:kiuJz3guxFQ:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=gX0IBD4q8PM:kiuJz3guxFQ:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=gX0IBD4q8PM:kiuJz3guxFQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=gX0IBD4q8PM:kiuJz3guxFQ:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/gX0IBD4q8PM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/</feedburner:origLink></item>
		<item>
		<title>Tips: Multiple pagination with will_paginate</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/0rzt7i0Hido/</link>
		<comments>http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/#comments</comments>
		<pubDate>Thu, 11 Aug 2011 13:07:10 +0000</pubDate>
		<dc:creator>Claudio</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[will_paginate]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1119</guid>
		<description><![CDATA[Will Paginate is a great and widely used gem for pagination in Ruby on Rails.

Sometimes you need to paginate multiple list on the same page.


This tip show you how to put a list of paginated products and a list of of paginated services on the same page with will_paginate.
The key point is to use a [...]]]></description>
			<content:encoded><![CDATA[<p>Will Paginate is a great and widely used gem for pagination in Ruby on Rails.</p>
<p>
Sometimes you need to <strong>paginate multiple list on the same page</strong>.
</p>
<p>
This <em>tip</em> show you how to put a list of paginated products and a list of of paginated services on the same page with <a href="https://github.com/mislav/will_paginate">will_paginate</a>.<br />
The key point is to use a custom param <em>param_name</em> in the view and also in the controller
</p>
<p>The view code is something like this:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># ...<br />
# products list here <br />
&nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= will_paginate <span style="color:#0066ff; font-weight:bold;">@products</span>, <span style="color:#ff3333; font-weight:bold;">:param_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'products_page'</span>, <span style="color:#ff3333; font-weight:bold;">:prev_label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'helpers.labels.previous'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:next_label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'helpers.labels.next'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
<br />
# services list here <br />
&nbsp; <span style="color:#006600; font-weight:bold;">&lt;%</span>= will_paginate <span style="color:#0066ff; font-weight:bold;">@services</span>, <span style="color:#ff3333; font-weight:bold;">:param_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'services_page'</span>, <span style="color:#ff3333; font-weight:bold;">:prev_label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'helpers.labels.previous'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#ff3333; font-weight:bold;">:next_label</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'helpers.labels.next'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span><br />
# ...</div></td></tr></tbody></table></div>
<p>And this is the code in the controller</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;"># ...</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> index<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@products</span> = current_company.<span style="color:#9900CC;">products</span>.<span style="color:#9900CC;">paginate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:products_page</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:per_page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@services</span> = current_company.<span style="color:#9900CC;">products</span>.<span style="color:#9900CC;">paginate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:services_page</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:per_page</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#008000; font-style:italic;"># ...</span></div></td></tr></tbody></table></div>
<p><!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'Tips: Multiple pagination with will_paginate' to Del.icio.us" alt="Add 'Tips: Multiple pagination with will_paginate' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'Tips: Multiple pagination with will_paginate' to digg" alt="Add 'Tips: Multiple pagination with will_paginate' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'Tips: Multiple pagination with will_paginate' to reddit" alt="Add 'Tips: Multiple pagination with will_paginate' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="Add 'Tips: Multiple pagination with will_paginate' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'Tips: Multiple pagination with will_paginate' to Technorati" alt="Add 'Tips: Multiple pagination with will_paginate' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'Tips: Multiple pagination with will_paginate' to Stumble Upon" alt="Add 'Tips: Multiple pagination with will_paginate' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'Tips: Multiple pagination with will_paginate' to Google Bookmarks" alt="Add 'Tips: Multiple pagination with will_paginate' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="Add 'Tips: Multiple pagination with will_paginate' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'Tips: Multiple pagination with will_paginate' to Rojo" alt="Add 'Tips: Multiple pagination with will_paginate' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'Tips: Multiple pagination with will_paginate' to OKnotizie" alt="Add 'Tips: Multiple pagination with will_paginate' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=Tips%3A+Multiple+pagination+with+will_paginate&amp;url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="Add 'Tips: Multiple pagination with will_paginate' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'Tips: Multiple pagination with will_paginate' to Diggita" alt="Add 'Tips: Multiple pagination with will_paginate' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;t=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'Tips: Multiple pagination with will_paginate' to FaceBook" alt="Add 'Tips: Multiple pagination with will_paginate' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate" title="Add 'Tips: Multiple pagination with will_paginate' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'Tips: Multiple pagination with will_paginate' to Upnews" alt="Add 'Tips: Multiple pagination with will_paginate' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="Add 'Tips: Multiple pagination with will_paginate' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'Tips: Multiple pagination with will_paginate' to Twitter" alt="Add 'Tips: Multiple pagination with will_paginate' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=Tips%3A+Multiple+pagination+with+will_paginate&amp;url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="Add 'Tips: Multiple pagination with will_paginate' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'Tips: Multiple pagination with will_paginate' to Technotizie" alt="Add 'Tips: Multiple pagination with will_paginate' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=Tips%3A+Multiple+pagination+with+will_paginate&amp;url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="Add 'Tips: Multiple pagination with will_paginate' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'Tips: Multiple pagination with will_paginate' to FriendFeed" alt="Add 'Tips: Multiple pagination with will_paginate' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/&amp;title=Tips%3A+Multiple+pagination+with+will_paginate&amp;srcURL=http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="Add 'Tips: Multiple pagination with will_paginate' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'Tips: Multiple pagination with will_paginate' to Google Buzz" alt="Add 'Tips: Multiple pagination with will_paginate' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="<!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:-->"><!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="<!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:-->"><!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:--></a></li><li><a href="http://blog.devinterface.com/2010/05/how-to-model-a-custom-search-form-in-rails/" title="<!--:en-->How to model a custom search form in Rails<!--:--><!--:it-->Come modellare una form di ricerca usando Rails<!--:-->"><!--:en-->How to model a custom search form in Rails<!--:--><!--:it-->Come modellare una form di ricerca usando Rails<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="<!--:en-->How to send email asynchronously using Devise and Rails3<!--:--><!--:it-->Come spedire email in modo asincrono con Devise e Rails3<!--:-->"><!--:en-->How to send email asynchronously using Devise and Rails3<!--:--><!--:it-->Come spedire email in modo asincrono con Devise e Rails3<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="<!--:en-->Ruby Enumerables: Operation on hashes<!--:--><!--:it-->Ruby Enumerables: Operazioni con le hash<!--:-->"><!--:en-->Ruby Enumerables: Operation on hashes<!--:--><!--:it-->Ruby Enumerables: Operazioni con le hash<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/UYER8o2W8DdwDxVSn7kpsragAAM/0/da"><img src="http://feedads.g.doubleclick.net/~a/UYER8o2W8DdwDxVSn7kpsragAAM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/UYER8o2W8DdwDxVSn7kpsragAAM/1/da"><img src="http://feedads.g.doubleclick.net/~a/UYER8o2W8DdwDxVSn7kpsragAAM/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=0rzt7i0Hido:RlbGbMbZW4U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=0rzt7i0Hido:RlbGbMbZW4U:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=0rzt7i0Hido:RlbGbMbZW4U:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=0rzt7i0Hido:RlbGbMbZW4U:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=0rzt7i0Hido:RlbGbMbZW4U:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/0rzt7i0Hido" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/</feedburner:origLink></item>
		<item>
		<title>Two step signup with Devise</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/dQOHHJHUOBU/</link>
		<comments>http://blog.devinterface.com/2011/05/two-step-signup-with-devise/#comments</comments>
		<pubDate>Wed, 11 May 2011 20:28:04 +0000</pubDate>
		<dc:creator>Claudio</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[devise]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[registration]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[signup]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1096</guid>
		<description><![CDATA[On my Ruby on Rails projects I usually use the Devise gem for user authentication.
In the last application I need to customize Devise so that users can register providing email address only. I will ask for a password only at the confirmation step.
After some tests, I come with this solutions.
1. First I need to overwrite [...]]]></description>
			<content:encoded><![CDATA[<p>On my Ruby on Rails projects I usually use the <a href="https://github.com/plataformatec/devise">Devise</a> gem for user authentication.</p>
<p>In the last application I need to customize Devise so that users can register providing email address only. I will ask for a password only at the confirmation step.<br />
After some tests, I come with this solutions.</p>
<p><strong>1.</strong> First I need to overwrite the ConfirmationsController, so in the routes.rb I set devise to use my custom controller (my model is called Account).<br />
I also need to define a custom controller for registrations so I can customize the registration view:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; devise_for <span style="color:#ff3333; font-weight:bold;">:accounts</span>, <span style="color:#ff3333; font-weight:bold;">:controllers</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:confirmations <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;confirmations&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:registrations</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;registrations&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; put <span style="color:#996600;">&quot;confirm_account&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:to</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;confirmations#confirm_account&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>As you can see I&#8217;ve also added a custom method, confirm_account that I will use in the fourth step, as you will see soon.</p>
<p><strong>2.</strong> Now I need to skip the devise built in password validation.<br />
To achieve this I wrote a custom initializer called devise_customization.rb in <em>/config/initalizers/</em> like this:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">module</span> Devise<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Models<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Validatable<br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> password_required?<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">false</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>So I have overwritten the default devise validatable module skipping the password validation.</p>
<p><strong>3.</strong>The next step is to customize views.<br />
Given I&#8217;m using a custom ConfirmationsController and RegistrationsController I have copied the default confirmations views under <em>/views/confirmations/</em> and the default registrations views under <em>/views/registrations/</em> and changed them according to my two step registration.</p>
<p>The <em>/registrations/new</em> view is something like this (I&#8217;m using <a href="http://haml-lang.com/">haml</a>)</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">= form_for<span style="color:#006600; font-weight:bold;">&#40;</span>resource, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> resource_name, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> account_registration_path<span style="color:#006600; font-weight:bold;">&#40;</span>@account<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; = devise_error_messages! &nbsp; &nbsp; <br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">p</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:email</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">email_field</span> <span style="color:#ff3333; font-weight:bold;">:email</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">clearfix</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">'Signup'</span><br />
&nbsp; = link_to <span style="color:#996600;">'Home'</span>, root_url<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>br<span style="color:#006600; font-weight:bold;">/</span> <br />
&nbsp; = render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/shared/links'</span></div></td></tr></tbody></table></div>
<p>Here I&#8217;ve just remove the password and password_confirmation fields.</p>
<p>The <em>/confirmations/show</em> view is something like this</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">= form_for<span style="color:#006600; font-weight:bold;">&#40;</span>resource, <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> confirm_account_path<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; = devise_error_messages! &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">p</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:email</span><br />
&nbsp; &nbsp; = <span style="color:#0066ff; font-weight:bold;">@account</span>.<span style="color:#9900CC;">email</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">hidden_field</span> <span style="color:#ff3333; font-weight:bold;">:confirmation_token</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">p</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:password</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">%</span>br<span style="color:#006600; font-weight:bold;">/</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">password_field</span> <span style="color:#ff3333; font-weight:bold;">:password</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">p</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">label</span> <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span><br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">%</span>br<span style="color:#006600; font-weight:bold;">/</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">password_field</span> <span style="color:#ff3333; font-weight:bold;">:password_confirmation</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span><span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">clearfix</span><br />
&nbsp; &nbsp; = f.<span style="color:#9900CC;">submit</span> <span style="color:#996600;">'Confirm Account'</span><br />
&nbsp; = link_to <span style="color:#996600;">'Home'</span>, root_url<br />
&nbsp; <span style="color:#006600; font-weight:bold;">%</span>br<span style="color:#006600; font-weight:bold;">/</span><br />
&nbsp; = render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'devise/shared/links'</span></div></td></tr></tbody></table></div>
<p><strong>4.</strong> Ok, once I&#8217;ve setup the views I have to write the new confirmation method in my ConfirmationsController. I can leave unchanged the RegistrationsController.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> ConfirmationsController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Devise::ConfirmationsController</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> show<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@account</span> = Account.<span style="color:#9900CC;">find_by_confirmation_token</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:confirmation_token</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> !@account.<span style="color:#9900CC;">present</span>?<br />
&nbsp; &nbsp; &nbsp; render_with_scope <span style="color:#ff3333; font-weight:bold;">:new</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> confirm_account<br />
&nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@account</span> = Account.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:account</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:confirmation_token</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@account</span>.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:account</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">and</span> <span style="color:#0066ff; font-weight:bold;">@account</span>.<span style="color:#9900CC;">password_match</span>?<br />
&nbsp; &nbsp; &nbsp; <span style="color:#0066ff; font-weight:bold;">@account</span> = Account.<span style="color:#9900CC;">confirm_by_token</span><span style="color:#006600; font-weight:bold;">&#40;</span>@account.<span style="color:#9900CC;">confirmation_token</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; set_flash_message <span style="color:#ff3333; font-weight:bold;">:notice</span>, <span style="color:#ff3333; font-weight:bold;">:confirmed</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; sign_in_and_redirect<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;account&quot;</span>, <span style="color:#0066ff; font-weight:bold;">@account</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span><br />
&nbsp; &nbsp; &nbsp; render <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;show&quot;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>The show method simply find the account to confirm by the devise token and render the show view.<br />
The key point is the <em>confirm_account</em> method where I find the account, update attributes and if password_match? return true I confirm the account calling the standard devise method <em>confirm_by_token</em></p>
<p><strong>5.</strong> The last thing to do is to define the password_match? method inside the Account model.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> Account <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span><br />
...<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> password_match?<br />
&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:password</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">'password not match'</span> <span style="color:#9966CC; font-weight:bold;">if</span> password != password_confirmation<br />
&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">errors</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:password</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">'you must provide a password'</span> <span style="color:#9966CC; font-weight:bold;">if</span> password.<span style="color:#9900CC;">blank</span>?<br />
&nbsp; &nbsp; password == password_confirmation <span style="color:#9966CC; font-weight:bold;">and</span> !password.<span style="color:#9900CC;">blank</span>?<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p><strong>That&#8217;s all!</strong><br />
Now you can star your rails server and signup in your application providing a password only at the confirmation step.<br />
<!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'Two step signup with Devise' to Del.icio.us" alt="Add 'Two step signup with Devise' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'Two step signup with Devise' to digg" alt="Add 'Two step signup with Devise' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'Two step signup with Devise' to reddit" alt="Add 'Two step signup with Devise' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="Add 'Two step signup with Devise' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'Two step signup with Devise' to Technorati" alt="Add 'Two step signup with Devise' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'Two step signup with Devise' to Stumble Upon" alt="Add 'Two step signup with Devise' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'Two step signup with Devise' to Google Bookmarks" alt="Add 'Two step signup with Devise' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="Add 'Two step signup with Devise' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'Two step signup with Devise' to Rojo" alt="Add 'Two step signup with Devise' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'Two step signup with Devise' to OKnotizie" alt="Add 'Two step signup with Devise' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=Two+step+signup+with+Devise&amp;url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="Add 'Two step signup with Devise' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'Two step signup with Devise' to Diggita" alt="Add 'Two step signup with Devise' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;t=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'Two step signup with Devise' to FaceBook" alt="Add 'Two step signup with Devise' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise" title="Add 'Two step signup with Devise' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'Two step signup with Devise' to Upnews" alt="Add 'Two step signup with Devise' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="Add 'Two step signup with Devise' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'Two step signup with Devise' to Twitter" alt="Add 'Two step signup with Devise' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=Two+step+signup+with+Devise&amp;url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="Add 'Two step signup with Devise' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'Two step signup with Devise' to Technotizie" alt="Add 'Two step signup with Devise' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=Two+step+signup+with+Devise&amp;url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="Add 'Two step signup with Devise' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'Two step signup with Devise' to FriendFeed" alt="Add 'Two step signup with Devise' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/&amp;title=Two+step+signup+with+Devise&amp;srcURL=http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="Add 'Two step signup with Devise' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'Two step signup with Devise' to Google Buzz" alt="Add 'Two step signup with Devise' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="<!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:-->"><!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="<!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:-->"><!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:--></a></li><li><a href="http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="<!--:en-->How to send email asynchronously using Devise and Rails3<!--:--><!--:it-->Come spedire email in modo asincrono con Devise e Rails3<!--:-->"><!--:en-->How to send email asynchronously using Devise and Rails3<!--:--><!--:it-->Come spedire email in modo asincrono con Devise e Rails3<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/05/how-to-model-a-custom-search-form-in-rails/" title="<!--:en-->How to model a custom search form in Rails<!--:--><!--:it-->Come modellare una form di ricerca usando Rails<!--:-->"><!--:en-->How to model a custom search form in Rails<!--:--><!--:it-->Come modellare una form di ricerca usando Rails<!--:--></a></li><li><a href="http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="<!--:en-->How to insert more Disqus comments box in a single page<!--:--><!--:it-->Inserire box di commento Disqus più volte nella stessa pagina<!--:-->"><!--:en-->How to insert more Disqus comments box in a single page<!--:--><!--:it-->Inserire box di commento Disqus più volte nella stessa pagina<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/Db3aGoj8H1vo1938vAStHe1Btw8/0/da"><img src="http://feedads.g.doubleclick.net/~a/Db3aGoj8H1vo1938vAStHe1Btw8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Db3aGoj8H1vo1938vAStHe1Btw8/1/da"><img src="http://feedads.g.doubleclick.net/~a/Db3aGoj8H1vo1938vAStHe1Btw8/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=dQOHHJHUOBU:D2o86irTeLQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=dQOHHJHUOBU:D2o86irTeLQ:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=dQOHHJHUOBU:D2o86irTeLQ:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=dQOHHJHUOBU:D2o86irTeLQ:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=dQOHHJHUOBU:D2o86irTeLQ:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/dQOHHJHUOBU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/05/two-step-signup-with-devise/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/05/two-step-signup-with-devise/</feedburner:origLink></item>
		<item>
		<title>We area launching Gruppi Emergenti</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/z6c8q9h5x4k/</link>
		<comments>http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 12:56:41 +0000</pubDate>
		<dc:creator>DevInterface</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Gruppi Emergenti]]></category>
		<category><![CDATA[rilascio]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1084</guid>
		<description><![CDATA[It&#8217;s coming the time for publish online Gruppi Emergenti, the new music portal that offers  a showcase for the bands, performers and live music venues in Italy.
The website is completely free, and allows you to create a page for your band or for your club and to publish your own live music events.
Through a localized [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s coming the time for publish online <a title="Gruppi Emergenti" href="http://www.gruppiemergenti.net" target="_blank">Gruppi Emergenti</a>, the new music portal that offers  a showcase for the bands, performers and live music venues in Italy.</p>
<p>The website is completely free, and allows you to create a page for your band or for your club and to publish your own live music events.</p>
<p>Through a localized search you can find all the upcoming events (live, concerts and so on) for a given period and in a given area.<br />
Google Maps integration also allows you to visually locate events and live clubs.</p>
<p>Registered users can receive every week a list of scheduled events for their favorite groups or locals with a personalized newsletter.</p>
<p>Gruppi Emergenti has also a notice-board for people who is searching instruments, musicians and courses.</p>
<p>It is also integrated with major social networks so users can publish the events created on the site directly on the profiles and pages of Facebook and Twitter.</p>
<p>The official launch is scheduled for <strong>Wednesday, April 20</strong>.</p>
<p>All users already registered during the presentation of the site lasted from March 1 to April 15 <strong>will receive their credentials to access by e-mail address immediately after the publication</strong>.</p>
<p>In addition, from all registered users, we extracted <strong>four winners of two months of free advertising</strong> on the portal.</p>
<p>You can see the list of winners in the picture below.</p>
<p style="text-align: center;"><img class="size-full wp-image-1085  aligncenter" title="Winners" src="http://blog.devinterface.com/wp-content/uploads/2011/04/Winners.jpg" alt="" width="432" height="318" /></p>
<p><strong>The winners will be contacted by email in the next hours with all the details for the publication of advertisement.</strong><!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'We area launching Gruppi Emergenti' to Del.icio.us" alt="Add 'We area launching Gruppi Emergenti' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'We area launching Gruppi Emergenti' to digg" alt="Add 'We area launching Gruppi Emergenti' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'We area launching Gruppi Emergenti' to reddit" alt="Add 'We area launching Gruppi Emergenti' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/" title="Add 'We area launching Gruppi Emergenti' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'We area launching Gruppi Emergenti' to Technorati" alt="Add 'We area launching Gruppi Emergenti' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'We area launching Gruppi Emergenti' to Stumble Upon" alt="Add 'We area launching Gruppi Emergenti' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'We area launching Gruppi Emergenti' to Google Bookmarks" alt="Add 'We area launching Gruppi Emergenti' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/" title="Add 'We area launching Gruppi Emergenti' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'We area launching Gruppi Emergenti' to Rojo" alt="Add 'We area launching Gruppi Emergenti' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'We area launching Gruppi Emergenti' to OKnotizie" alt="Add 'We area launching Gruppi Emergenti' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=We+area+launching+Gruppi+Emergenti&amp;url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/" title="Add 'We area launching Gruppi Emergenti' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'We area launching Gruppi Emergenti' to Diggita" alt="Add 'We area launching Gruppi Emergenti' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;t=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'We area launching Gruppi Emergenti' to FaceBook" alt="Add 'We area launching Gruppi Emergenti' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti" title="Add 'We area launching Gruppi Emergenti' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'We area launching Gruppi Emergenti' to Upnews" alt="Add 'We area launching Gruppi Emergenti' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/" title="Add 'We area launching Gruppi Emergenti' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'We area launching Gruppi Emergenti' to Twitter" alt="Add 'We area launching Gruppi Emergenti' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=We+area+launching+Gruppi+Emergenti&amp;url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/" title="Add 'We area launching Gruppi Emergenti' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'We area launching Gruppi Emergenti' to Technotizie" alt="Add 'We area launching Gruppi Emergenti' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=We+area+launching+Gruppi+Emergenti&amp;url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/" title="Add 'We area launching Gruppi Emergenti' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'We area launching Gruppi Emergenti' to FriendFeed" alt="Add 'We area launching Gruppi Emergenti' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/&amp;title=We+area+launching+Gruppi+Emergenti&amp;srcURL=http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/" title="Add 'We area launching Gruppi Emergenti' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'We area launching Gruppi Emergenti' to Google Buzz" alt="Add 'We area launching Gruppi Emergenti' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="<!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:-->"><!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:--></a></li><li><a href="http://blog.devinterface.com/2009/10/system-information-application-for-nodia-s60v5-phones/" title="<!--:en-->System Information application for Nokia S60v5 phones<!--:--><!--:it-->Applicazione System Information per telefoni Nokia S60v5<!--:-->"><!--:en-->System Information application for Nokia S60v5 phones<!--:--><!--:it-->Applicazione System Information per telefoni Nokia S60v5<!--:--></a></li><li><a href="http://blog.devinterface.com/2009/11/c-features/" title="<!--:en-->C# features<!--:--><!--:it-->Caratteristiche di C#<!--:-->"><!--:en-->C# features<!--:--><!--:it-->Caratteristiche di C#<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/06/rails-best-practices-introduction/" title="<!--:en-->Rails Best Practices: introduction<!--:--><!--:it-->Rails Best Practices: introduzione<!--:-->"><!--:en-->Rails Best Practices: introduction<!--:--><!--:it-->Rails Best Practices: introduzione<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/05/top-10-firefox-addons/" title="<!--:en-->Top 10 Firefox addons for web developers<!--:--><!--:it-->I 10 migliori Firefox addon per web developer<!--:-->"><!--:en-->Top 10 Firefox addons for web developers<!--:--><!--:it-->I 10 migliori Firefox addon per web developer<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/OkwEHPAfFDCf2OZH6_N3JYbCKzs/0/da"><img src="http://feedads.g.doubleclick.net/~a/OkwEHPAfFDCf2OZH6_N3JYbCKzs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/OkwEHPAfFDCf2OZH6_N3JYbCKzs/1/da"><img src="http://feedads.g.doubleclick.net/~a/OkwEHPAfFDCf2OZH6_N3JYbCKzs/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=z6c8q9h5x4k:rUtguV5IoPY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=z6c8q9h5x4k:rUtguV5IoPY:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=z6c8q9h5x4k:rUtguV5IoPY:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=z6c8q9h5x4k:rUtguV5IoPY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=z6c8q9h5x4k:rUtguV5IoPY:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/z6c8q9h5x4k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/04/we-area-launching-gruppi-emergenti/</feedburner:origLink></item>
		<item>
		<title>Prevent registration of reserved login</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/3aA98_-vXOQ/</link>
		<comments>http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 08:34:47 +0000</pubDate>
		<dc:creator>Claudio</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[login reservation]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1074</guid>
		<description><![CDATA[Every time you create a web application where users can register, it is good to exclude some login or username so that they can not be used.
 A classic example is the login &#8220;admin&#8221;.
I believe that no one wishes that in its application will be a registered user with the username &#8220;admin&#8221; then can contact [...]]]></description>
			<content:encoded><![CDATA[<p>Every time you create a web application where users can register, it is good to exclude some login or username so that they can not be used.<br />
 A classic example is the login &#8220;admin&#8221;.<br />
I believe that no one wishes that in its application will be a registered user with the username &#8220;admin&#8221; then can contact other users by pretending to be the true administrator.<br />
The same will be valid for others logins like &#8220;root&#8221;.</p>
<p>It is therefore necessary to define a <strong>list of reserved names</strong>.<br />
Fortunately, developing with Ruby on Rails is very easy to implement this functionality by using the  <strong>validates_exclusion_of</strong> validator up to version 2.3.8 of Rails</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
&nbsp; validates_exclusion_of <span style="color:#ff3333; font-weight:bold;">:login</span>, <br />
&nbsp; &nbsp; :<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;admin&quot;</span>, <span style="color:#996600;">&quot;root&quot;</span>, <span style="color:#996600;">&quot;administrator&quot;</span>, <span style="color:#996600;">&quot;superuser&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;is reserved&quot;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>or by using <strong>validates</strong> with the <strong>:exclusion</strong> parameter if you&#8217;re developing with Rails 3.x</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
validates <span style="color:#ff3333; font-weight:bold;">:login</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:exclusion</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;admin&quot;</span>, <span style="color:#996600;">&quot;root&quot;</span>, <span style="color:#996600;">&quot;administrator&quot;</span>, <span style="color:#996600;">&quot;superuser&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:message</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;is reserved&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>In this way, anyone trying to create an account with login &#8220;admin&#8221; gets an error message indicating that the name is reserved.<br />
It should however be borne in mind that &#8220;validates_exclusion_of&#8221; and also &#8220;validates: exclusion&#8221; methods <strong>are case sensitive</strong>.<br />
This means that, with this first implementation, a user who tries to register as &#8220;Admin&#8221; will succeed.</p>
<p>To overcome this problem the easiest thing to do is add a <strong>before_filter</strong> to convert the login entered by user in all lowercase letters before validates it.<br />
Here is the complete solution for Rails 2.3.x:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
&nbsp; <br />
&nbsp; before_validation <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>u<span style="color:#006600; font-weight:bold;">|</span> u.<span style="color:#9900CC;">login</span>.<span style="color:#9900CC;">downcase</span>! <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <br />
&nbsp; validates_exclusion_of <span style="color:#ff3333; font-weight:bold;">:login</span>, <br />
&nbsp; &nbsp; :<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;admin&quot;</span>, <span style="color:#996600;">&quot;root&quot;</span>, <span style="color:#996600;">&quot;administrator&quot;</span>, <span style="color:#996600;">&quot;superuser&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <br />
&nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;is reserved&quot;</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>and the equivalent solution for Rails 3:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
<br />
&nbsp; before_validation <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>u<span style="color:#006600; font-weight:bold;">|</span> u.<span style="color:#9900CC;">login</span>.<span style="color:#9900CC;">downcase</span>! <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <br />
&nbsp; validates <span style="color:#ff3333; font-weight:bold;">:login</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:exclusion</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:<span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;admin&quot;</span>, <span style="color:#996600;">&quot;root&quot;</span>, <span style="color:#996600;">&quot;administrator&quot;</span>, <span style="color:#996600;">&quot;superuser&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:message</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;is reserved&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>This method has the disadvantage of converting all login lowercase not allowing user to register two &#8220;equal&#8221; but with different case logins.<br />
This is a  solution that can be acceptable in many cases.<br />
However, <strong>if you need to preserve the case-sensitive login</strong> as entered by users, you can always implement a custom validation method:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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><br />
&nbsp; validate <span style="color:#ff3333; font-weight:bold;">:excluded_login</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> excluded_login<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span> admin root administrator superuser <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>reserved_login<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; user.<span style="color:#9900CC;">errors</span>.<span style="color:#9900CC;">add</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:login</span>, <span style="color:#996600;">&quot;is reserved&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> user.<span style="color:#9900CC;">login</span>.<span style="color:#9900CC;">downcase</span> == reserved_login<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div>
<p>Have you ever implemented a solution like this? Do you know a better way to achieve it?<!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'Prevent registration of reserved login' to Del.icio.us" alt="Add 'Prevent registration of reserved login' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'Prevent registration of reserved login' to digg" alt="Add 'Prevent registration of reserved login' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'Prevent registration of reserved login' to reddit" alt="Add 'Prevent registration of reserved login' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="Add 'Prevent registration of reserved login' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'Prevent registration of reserved login' to Technorati" alt="Add 'Prevent registration of reserved login' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'Prevent registration of reserved login' to Stumble Upon" alt="Add 'Prevent registration of reserved login' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'Prevent registration of reserved login' to Google Bookmarks" alt="Add 'Prevent registration of reserved login' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="Add 'Prevent registration of reserved login' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'Prevent registration of reserved login' to Rojo" alt="Add 'Prevent registration of reserved login' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'Prevent registration of reserved login' to OKnotizie" alt="Add 'Prevent registration of reserved login' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=Prevent+registration+of+reserved+login&amp;url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="Add 'Prevent registration of reserved login' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'Prevent registration of reserved login' to Diggita" alt="Add 'Prevent registration of reserved login' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;t=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'Prevent registration of reserved login' to FaceBook" alt="Add 'Prevent registration of reserved login' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login" title="Add 'Prevent registration of reserved login' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'Prevent registration of reserved login' to Upnews" alt="Add 'Prevent registration of reserved login' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="Add 'Prevent registration of reserved login' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'Prevent registration of reserved login' to Twitter" alt="Add 'Prevent registration of reserved login' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=Prevent+registration+of+reserved+login&amp;url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="Add 'Prevent registration of reserved login' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'Prevent registration of reserved login' to Technotizie" alt="Add 'Prevent registration of reserved login' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=Prevent+registration+of+reserved+login&amp;url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="Add 'Prevent registration of reserved login' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'Prevent registration of reserved login' to FriendFeed" alt="Add 'Prevent registration of reserved login' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/&amp;title=Prevent+registration+of+reserved+login&amp;srcURL=http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="Add 'Prevent registration of reserved login' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'Prevent registration of reserved login' to Google Buzz" alt="Add 'Prevent registration of reserved login' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="<!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:-->"><!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="<!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:-->"><!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/09/rails-best-practices-6-filters-and-helpers-file/" title="<!--:en-->Rails Best Practices 6: Filters and helpers file<!--:--><!--:it-->Rails Best Practices 6: Filtri e file helper<!--:-->"><!--:en-->Rails Best Practices 6: Filters and helpers file<!--:--><!--:it-->Rails Best Practices 6: Filtri e file helper<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/06/rails-best-practices-introduction/" title="<!--:en-->Rails Best Practices: introduction<!--:--><!--:it-->Rails Best Practices: introduzione<!--:-->"><!--:en-->Rails Best Practices: introduction<!--:--><!--:it-->Rails Best Practices: introduzione<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/06/partial-validation-in-rails/" title="<!--:en-->Partial Validation in Rails<!--:--><!--:it-->Validazione Parziale in Rails<!--:-->"><!--:en-->Partial Validation in Rails<!--:--><!--:it-->Validazione Parziale in Rails<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/ar2vQvVlZjhSyKjwfT2wHjXkO04/0/da"><img src="http://feedads.g.doubleclick.net/~a/ar2vQvVlZjhSyKjwfT2wHjXkO04/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ar2vQvVlZjhSyKjwfT2wHjXkO04/1/da"><img src="http://feedads.g.doubleclick.net/~a/ar2vQvVlZjhSyKjwfT2wHjXkO04/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=3aA98_-vXOQ:tApfZmSkuVo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=3aA98_-vXOQ:tApfZmSkuVo:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=3aA98_-vXOQ:tApfZmSkuVo:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=3aA98_-vXOQ:tApfZmSkuVo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=3aA98_-vXOQ:tApfZmSkuVo:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/3aA98_-vXOQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/</feedburner:origLink></item>
		<item>
		<title>A new layout easier and more spacious</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/V7cB08qlzSo/</link>
		<comments>http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 12:56:09 +0000</pubDate>
		<dc:creator>DevInterface</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Road to DevInterface]]></category>
		<category><![CDATA[DevInterface]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[restyling]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1067</guid>
		<description><![CDATA[In the last days we have spent a bit of our time to do a full redesign of our website and our blog.
The result is what you are looking while reading this article.
Specifically, the innovations we introduced in both the theme of the blog and the web site are:

Wider layout splitted into two columns also [...]]]></description>
			<content:encoded><![CDATA[<p>In the last days we have spent a bit of our time to do a full redesign of <a title="DevInterface" href="http://www.devinterface.com">our website</a> and <a title="DevInterface Blog" href="http://blog.devinterface.com">our blog</a>.</p>
<p>The result is what you are looking while reading this article.</p>
<p>Specifically, the innovations we introduced in both the theme of the blog and the web site are:</p>
<ul>
<li>Wider layout splitted into two columns also for the website</li>
<li>Blog contents with more space, which is very useful when showing code snippets</li>
<li>A wide and straight header that shows the key points of each page</li>
<li>A wider footer with all our references and the latest posts from Twitter (on the site, even the latest blog post)</li>
<li>A slider both on the homepage of the blog and the web site that visually sums up (at least in part) what we do</li>
<li>The &#8220;portfolio&#8221; page completely redesigned</li>
<li>The &#8220;about us&#8221; page with a more dynamic look</li>
</ul>
<p>From a technical standpoint the site has been rewritten using Ruby on Rails 3.0.5 and jQuery while the blog engine is always the  well proven Wordpress.</p>
<p>Do you like the new design? We are waiting for your comments!<!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'A new layout easier and more spacious' to Del.icio.us" alt="Add 'A new layout easier and more spacious' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'A new layout easier and more spacious' to digg" alt="Add 'A new layout easier and more spacious' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'A new layout easier and more spacious' to reddit" alt="Add 'A new layout easier and more spacious' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="Add 'A new layout easier and more spacious' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'A new layout easier and more spacious' to Technorati" alt="Add 'A new layout easier and more spacious' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'A new layout easier and more spacious' to Stumble Upon" alt="Add 'A new layout easier and more spacious' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'A new layout easier and more spacious' to Google Bookmarks" alt="Add 'A new layout easier and more spacious' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="Add 'A new layout easier and more spacious' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'A new layout easier and more spacious' to Rojo" alt="Add 'A new layout easier and more spacious' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'A new layout easier and more spacious' to OKnotizie" alt="Add 'A new layout easier and more spacious' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=A+new+layout+easier+and+more+spacious&amp;url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="Add 'A new layout easier and more spacious' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'A new layout easier and more spacious' to Diggita" alt="Add 'A new layout easier and more spacious' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;t=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'A new layout easier and more spacious' to FaceBook" alt="Add 'A new layout easier and more spacious' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious" title="Add 'A new layout easier and more spacious' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'A new layout easier and more spacious' to Upnews" alt="Add 'A new layout easier and more spacious' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="Add 'A new layout easier and more spacious' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'A new layout easier and more spacious' to Twitter" alt="Add 'A new layout easier and more spacious' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=A+new+layout+easier+and+more+spacious&amp;url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="Add 'A new layout easier and more spacious' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'A new layout easier and more spacious' to Technotizie" alt="Add 'A new layout easier and more spacious' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=A+new+layout+easier+and+more+spacious&amp;url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="Add 'A new layout easier and more spacious' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'A new layout easier and more spacious' to FriendFeed" alt="Add 'A new layout easier and more spacious' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/&amp;title=A+new+layout+easier+and+more+spacious&amp;srcURL=http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="Add 'A new layout easier and more spacious' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'A new layout easier and more spacious' to Google Buzz" alt="Add 'A new layout easier and more spacious' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2010/12/ruby-on-rails-and-jquery-multiselect-with-checkbox/" title="<!--:en-->Ruby on Rails and jQuery: multiselect with checkbox<!--:--><!--:it-->Ruby on Rails e jQuery: multiselect con checkbox<!--:-->"><!--:en-->Ruby on Rails and jQuery: multiselect with checkbox<!--:--><!--:it-->Ruby on Rails e jQuery: multiselect con checkbox<!--:--></a></li><li><a href="http://blog.devinterface.com/2012/01/how-to-insert-more-disqus-box-in-single-page/" title="<!--:en-->How to insert more Disqus comments box in a single page<!--:--><!--:it-->Inserire box di commento Disqus più volte nella stessa pagina<!--:-->"><!--:en-->How to insert more Disqus comments box in a single page<!--:--><!--:it-->Inserire box di commento Disqus più volte nella stessa pagina<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="<!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:-->"><!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="<!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:-->"><!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="<!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:-->"><!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/5fe_lcx41yuUGaRJ6p4Hd8cyigo/0/da"><img src="http://feedads.g.doubleclick.net/~a/5fe_lcx41yuUGaRJ6p4Hd8cyigo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/5fe_lcx41yuUGaRJ6p4Hd8cyigo/1/da"><img src="http://feedads.g.doubleclick.net/~a/5fe_lcx41yuUGaRJ6p4Hd8cyigo/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=V7cB08qlzSo:BvyT7B1SMSA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=V7cB08qlzSo:BvyT7B1SMSA:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=V7cB08qlzSo:BvyT7B1SMSA:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=V7cB08qlzSo:BvyT7B1SMSA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=V7cB08qlzSo:BvyT7B1SMSA:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/V7cB08qlzSo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/</feedburner:origLink></item>
		<item>
		<title>How to send email asynchronously using Devise and Rails3</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/IIx6V214Xqg/</link>
		<comments>http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 14:47:16 +0000</pubDate>
		<dc:creator>Stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[delayed_job]]></category>
		<category><![CDATA[devise]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1057</guid>
		<description><![CDATA[	Hello everyone.

	I&#8217;d show a workaround to send email asynchronously using Devise and Rails3.

	Suppose we have already up and running our application with Devise and delayed_job correctly installed.

	A first attempt was to add in config/initializers the following file (devise_async.rb):

	12345678910111213141516#devise_async.rb
module Devise
&#160; module Models
&#160; &#160; module Confirmable
&#160; &#160; &#160; handle_asynchronously :send_confirmation_instructions
&#160; &#160; end

&#160; &#160; module Recoverable
&#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[	<p>Hello everyone.</p>

	<p>I&#8217;d show a workaround to send email asynchronously using Devise and Rails3.</p>

	<p>Suppose we have already up and running our application with <a href="https://github.com/plataformatec/devise" title="">Devise</a> and <a href="https://github.com/collectiveidea/delayed_job/tree/v3.0" title="">delayed_job</a> correctly installed.</p>

	<p>A first attempt was to add in config/initializers the following file (devise_async.rb):</p>

	<p><div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#devise_async.rb</span><br />
<span style="color:#9966CC; font-weight:bold;">module</span> Devise<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Models<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Confirmable<br />
&nbsp; &nbsp; &nbsp; handle_asynchronously <span style="color:#ff3333; font-weight:bold;">:send_confirmation_instructions</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Recoverable<br />
&nbsp; &nbsp; &nbsp; handle_asynchronously <span style="color:#ff3333; font-weight:bold;">:send_reset_password_instructions</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Lockable<br />
&nbsp; &nbsp; &nbsp; handle_asynchronously <span style="color:#ff3333; font-weight:bold;">:send_unlock_instructions</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div></p>

	<p>This workaround has worked in part: the send method has been properly enqueued in the database, but when delayed_job tries to fire the job, the following error is raised:</p>

	<p><div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">User#</span>send_confirmation_instructions_without_delay failed with NoMethodError: undefined method <span style="color: #ff0000;">'send_confirmation_instructions_without_delay'</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #666666; font-style: italic;">#&lt;User:0x000000032f87c8&gt; - 1 failed attempts</span><br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span>Worker<span style="color: #7a0874; font-weight: bold;">&#40;</span>host:stefano-desktop pid:<span style="color: #000000;">13153</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></div></td></tr></tbody></table></div></p>

	<p>As you can see, the job is trying to call the wrong send method: send_confirmation_instructions_without_delay.</p>

	<p>At this point, I&#8217;ve implemented an even more dirty hack, overriding Devise&#8217;s methods using the syntax specified by intridea to send emails in the background:</p>

	<p><div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#devise_async.rb</span><br />
<span style="color:#9966CC; font-weight:bold;">module</span> Devise<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Models<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Confirmable<br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Send confirmation instructions by email</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> send_confirmation_instructions<br />
&nbsp; &nbsp; &nbsp; &nbsp; generate_confirmation_token! <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">confirmation_token</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?<br />
&nbsp; &nbsp; &nbsp; &nbsp; ::Devise.<span style="color:#9900CC;">mailer</span>.<span style="color:#9900CC;">delay</span>.<span style="color:#9900CC;">confirmation_instructions</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Recoverable<br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Resets reset password token and send reset password instructions by email</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> send_reset_password_instructions<br />
&nbsp; &nbsp; &nbsp; &nbsp; generate_reset_password_token!<br />
&nbsp; &nbsp; &nbsp; &nbsp; ::Devise.<span style="color:#9900CC;">mailer</span>.<span style="color:#9900CC;">delay</span>.<span style="color:#9900CC;">reset_password_instructions</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Lockable<br />
&nbsp; &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># Send unlock instructions by email</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> send_unlock_instructions<br />
&nbsp; &nbsp; &nbsp; &nbsp; ::Devise.<span style="color:#9900CC;">mailer</span>.<span style="color:#9900CC;">delay</span>.<span style="color:#9900CC;">unlock_instructions</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div></p>

	<p>This solution, however, is too tied to the implementation of Devise and is therefore not a good one (besides being really really dirty).</p>

	<p>The latest idea, which represents the solution I&#8217;ve used is implemented as follows: use the alias_method in this way:</p>

	<p><div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#008000; font-style:italic;">#devise_async.rb</span><br />
<span style="color:#9966CC; font-weight:bold;">module</span> Devise<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Models<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Confirmable<br />
&nbsp; &nbsp; &nbsp; alias_method <span style="color:#ff3333; font-weight:bold;">:send_confirmation_instructions_without_delay</span>, <span style="color:#ff3333; font-weight:bold;">:send_confirmation_instructions</span><br />
&nbsp; &nbsp; &nbsp; handle_asynchronously <span style="color:#ff3333; font-weight:bold;">:send_confirmation_instructions</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Recoverable<br />
&nbsp; &nbsp; &nbsp; alias_method <span style="color:#ff3333; font-weight:bold;">:send_reset_password_instructions_without_delay</span>, <span style="color:#ff3333; font-weight:bold;">:send_reset_password_instructions</span><br />
&nbsp; &nbsp; &nbsp; handle_asynchronously <span style="color:#ff3333; font-weight:bold;">:send_reset_password_instructions</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">module</span> Lockable<br />
&nbsp; &nbsp; &nbsp; alias_method <span style="color:#ff3333; font-weight:bold;">:send_unlock_instructions_without_delay</span>, <span style="color:#ff3333; font-weight:bold;">:send_unlock_instructions</span><br />
&nbsp; &nbsp; &nbsp; handle_asynchronously <span style="color:#ff3333; font-weight:bold;">:send_unlock_instructions</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></td></tr></tbody></table></div></p>

	<p>This latest hack works a treat; is not the best but let you send mail with Devise asynchronously.</p>

	<p>If you have any better solutions, do not hesitate to share.<!-- Social Bookmarking Reloaded BEGIN --><div class="social_bookmark"><em>Share on:</em><br />
<a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Del.icio.us" alt="Add 'How to send email asynchronously using Devise and Rails3' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&#038;url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'How to send email asynchronously using Devise and Rails3' to digg" alt="Add 'How to send email asynchronously using Devise and Rails3' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'How to send email asynchronously using Devise and Rails3' to reddit" alt="Add 'How to send email asynchronously using Devise and Rails3' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="Add 'How to send email asynchronously using Devise and Rails3' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Technorati" alt="Add 'How to send email asynchronously using Devise and Rails3' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Stumble Upon" alt="Add 'How to send email asynchronously using Devise and Rails3' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&#038;output=popup&#038;bkmk=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Google Bookmarks" alt="Add 'How to send email asynchronously using Devise and Rails3' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="Add 'How to send email asynchronously using Devise and Rails3' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Rojo" alt="Add 'How to send email asynchronously using Devise and Rails3' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'How to send email asynchronously using Devise and Rails3' to OKnotizie" alt="Add 'How to send email asynchronously using Devise and Rails3' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=How+to+send+email+asynchronously+using+Devise+and+Rails3&#038;url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="Add 'How to send email asynchronously using Devise and Rails3' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Diggita" alt="Add 'How to send email asynchronously using Devise and Rails3' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;t=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'How to send email asynchronously using Devise and Rails3' to FaceBook" alt="Add 'How to send email asynchronously using Devise and Rails3' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3" title="Add 'How to send email asynchronously using Devise and Rails3' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Upnews" alt="Add 'How to send email asynchronously using Devise and Rails3' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="Add 'How to send email asynchronously using Devise and Rails3' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Twitter" alt="Add 'How to send email asynchronously using Devise and Rails3' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3&#038;url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="Add 'How to send email asynchronously using Devise and Rails3' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Technotizie" alt="Add 'How to send email asynchronously using Devise and Rails3' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=How+to+send+email+asynchronously+using+Devise+and+Rails3&#038;url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="Add 'How to send email asynchronously using Devise and Rails3' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'How to send email asynchronously using Devise and Rails3' to FriendFeed" alt="Add 'How to send email asynchronously using Devise and Rails3' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/&#038;title=How+to+send+email+asynchronously+using+Devise+and+Rails3&#038;srcURL=http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/" title="Add 'How to send email asynchronously using Devise and Rails3' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'How to send email asynchronously using Devise and Rails3' to Google Buzz" alt="Add 'How to send email asynchronously using Devise and Rails3' to Google Buzz" /></a></div><br />
<!-- Social Bookmarking Reloaded END --></p>
 <h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="<!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:-->"><!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="<!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:-->"><!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="<!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:-->"><!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:--></a></li><li><a href="http://blog.devinterface.com/2010/09/different-layout-for-the-same-controller/" title="<!--:en-->Different layout for the same controller<!--:--><!--:it-->Layout differenti per lo stesso controller<!--:-->"><!--:en-->Different layout for the same controller<!--:--><!--:it-->Layout differenti per lo stesso controller<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/09/rails-best-practices-6-filters-and-helpers-file/" title="<!--:en-->Rails Best Practices 6: Filters and helpers file<!--:--><!--:it-->Rails Best Practices 6: Filtri e file helper<!--:-->"><!--:en-->Rails Best Practices 6: Filters and helpers file<!--:--><!--:it-->Rails Best Practices 6: Filtri e file helper<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/Q_2Ma1PkLSYFpdd_jeKUS9v80Gc/0/da"><img src="http://feedads.g.doubleclick.net/~a/Q_2Ma1PkLSYFpdd_jeKUS9v80Gc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Q_2Ma1PkLSYFpdd_jeKUS9v80Gc/1/da"><img src="http://feedads.g.doubleclick.net/~a/Q_2Ma1PkLSYFpdd_jeKUS9v80Gc/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=IIx6V214Xqg:qtQ891vSSVY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=IIx6V214Xqg:qtQ891vSSVY:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=IIx6V214Xqg:qtQ891vSSVY:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=IIx6V214Xqg:qtQ891vSSVY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=IIx6V214Xqg:qtQ891vSSVY:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/IIx6V214Xqg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/</feedburner:origLink></item>
		<item>
		<title>How to implement two dropdowns dependent on each other using Django and jQuery</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/9e0r_GedIfI/</link>
		<comments>http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 15:40:46 +0000</pubDate>
		<dc:creator>Stefano</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=1053</guid>
		<description><![CDATA[Hello everyone.
With today&#8217;s article I want to show how to implement two dropdowns dependent on each other using Django and jQuery.
Suppose we have a 1-N relationship between car brands and car models: we want to show the list of brands in the first dropdown; then once you have selected a brand, the second dropdown will [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone.</p>
<p>With today&#8217;s article I want to show how to implement two dropdowns dependent on each other using Django and jQuery.</p>
<p>Suppose we have a 1-N relationship between car brands and car models: we want to show the list of brands in the first dropdown; then once you have selected a brand, the second dropdown will show a list of filtered models for that brand.</p>
<p>Suppose we have our models defined as follows:</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#models.py</span><br />
<span style="color: #ff7700;font-weight:bold;">class</span> VehicleBrand<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; description <span style="color: #66cc66;">=</span> models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length<span style="color: #66cc66;">=</span><span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #dc143c;">code</span> <span style="color: #66cc66;">=</span> models.<span style="color: black;">SlugField</span><span style="color: black;">&#40;</span>primary_key<span style="color: #66cc66;">=</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">class</span> VehicleModel<span style="color: black;">&#40;</span>models.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; description <span style="color: #66cc66;">=</span> models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length<span style="color: #66cc66;">=</span><span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #dc143c;">code</span> <span style="color: #66cc66;">=</span> models.<span style="color: black;">SlugField</span><span style="color: black;">&#40;</span>primary_key<span style="color: #66cc66;">=</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; brand <span style="color: #66cc66;">=</span> models.<span style="color: black;">ForeignKey</span><span style="color: black;">&#40;</span>VehicleBrand<span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>Let&#8217;s write a templatetag that will be included in our templates:</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#templatetags.py</span><br />
<span style="color: #ff7700;font-weight:bold;">from</span> models <span style="color: #ff7700;font-weight:bold;">import</span> VehicleBrand<br />
<br />
<span style="color: #ff7700;font-weight:bold;">from</span> django <span style="color: #ff7700;font-weight:bold;">import</span> template<br />
<br />
register <span style="color: #66cc66;">=</span> template.<span style="color: black;">Library</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #66cc66;">@</span>register.<span style="color: black;">inclusion_tag</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;brand_model_select.html&quot;</span><span style="color: black;">&#41;</span><br />
<span style="color: #ff7700;font-weight:bold;">def</span> brand_model_select<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; brand_list <span style="color: #66cc66;">=</span> VehicleBrand.<span style="color: black;">objects</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span><span style="color: #483d8b;">'brand_list'</span> : brand_list<span style="color: black;">&#125;</span></div></td></tr></tbody></table></div>
<p>As you can see, the templatetag requires a support html template, defined as follow:</p>
<div class="codecolorer-container html4strict vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">&lt;!-- brand_model_select.html --&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;get&quot;</span> <span style="color: #000066;">accept-charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">select</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;brand&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;brand&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Z&quot;</span>&gt;</span>Select a brand<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; {% for brand in brand_list %}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;{{ brand.code}}&quot;</span>&gt;</span>{{ brand.description }}<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; {% endfor %}<br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">select</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">select</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;model&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;model&quot;</span> <span style="color: #000066;">disabled</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;true&quot;</span>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span>Select a model<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/select.html"><span style="color: #000000; font-weight: bold;">select</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; $(document).ready(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;select#brand&quot;).change(function() {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($(this).val() == 'Z') {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;select#model&quot;).html(&quot;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span>Select a model<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span>&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;select#model&quot;).attr('disabled', true);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var url = &quot;/brand/&quot; + $(this).val() + &quot;/all_json_models&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var brand = $(this).val();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$.getJSON(url, function(models) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var options = '<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Z&quot;</span>&gt;</span>Select a model<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span>';<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (var i = 0; i <span style="color: #009900;">&lt; models.length; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></span><br />
<span style="color: #009900;"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; options +<span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'&lt;option value=&quot;'</span> + models<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.pk + <span style="color: #ff0000;">'&quot;&gt;</span></span>' + models[i].fields['description'] + '<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/option.html"><span style="color: #000000; font-weight: bold;">option</span></a>&gt;</span>';<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;select#model&quot;).html(options);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;select#model option:first&quot;).attr('selected', 'selected');<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;select#model&quot;).attr('disabled', false);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;select#model&quot;).change(function(vent) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($(this).val() == -1) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;myAwesomeFunctionToCallWhenAModelIsSelected();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br />
&nbsp; &nbsp; }<br />
<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Please note that once a brand is selected, the following url will be invoked via Ajax request:<br />
/brand/&#8221;selected_brand_code&#8221;/all_json_models</p>
<p>then we need to define a view to handle this request:</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#views.py</span><br />
<span style="color: #ff7700;font-weight:bold;">def</span> all_json_models<span style="color: black;">&#40;</span>request<span style="color: #66cc66;">,</span> brand<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; current_brand <span style="color: #66cc66;">=</span> VehicleBrand.<span style="color: black;">objects</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">code</span><span style="color: #66cc66;">=</span>brand<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; models <span style="color: #66cc66;">=</span> VehicleModel.<span style="color: black;">objects</span>.<span style="color: #008000;">all</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: #008000;">filter</span><span style="color: black;">&#40;</span>brand<span style="color: #66cc66;">=</span>current_brand<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; json_models <span style="color: #66cc66;">=</span> serializers.<span style="color: black;">serialize</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;json&quot;</span><span style="color: #66cc66;">,</span> models<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponse<span style="color: black;">&#40;</span>json_models<span style="color: #66cc66;">,</span> mimetype<span style="color: #66cc66;">=</span><span style="color: #483d8b;">&quot;application/javascript&quot;</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>
<p>and in urls.py:</p>
<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#urls.py</span><br />
...<br />
<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^brand/(?P&lt;brand&gt;[-<span style="color: #000099; font-weight: bold;">\w</span>]+)/all_json_models/$'</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">'all_json_models'</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span></div></td></tr></tbody></table></div>
<p>Finally, the javascript method myAwesomeFunctionToCallWhenAModelIsSelected() will be invoked when a model will be selected.<!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Del.icio.us" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to digg" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to reddit" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Technorati" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Stumble Upon" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Google Bookmarks" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Rojo" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to OKnotizie" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery&amp;url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Diggita" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;t=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to FaceBook" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Upnews" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Twitter" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery&amp;url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Technotizie" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery&amp;url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to FriendFeed" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/&amp;title=How+to+implement+two+dropdowns+dependent+on+each+other+using+Django+and+jQuery&amp;srcURL=http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Google Buzz" alt="Add 'How to implement two dropdowns dependent on each other using Django and jQuery' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/03/new-layout-easier-and-spacious/" title="<!--:en-->A new layout easier and more spacious<!--:--><!--:it-->Un nuovo layout più semplice e spazioso<!--:-->"><!--:en-->A new layout easier and more spacious<!--:--><!--:it-->Un nuovo layout più semplice e spazioso<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="<!--:en-->How to create a custom feed in Django using the Syndication Feed Framework<!--:--><!--:it-->Creare un custom feed in Django con il Syndication Feed Framework<!--:-->"><!--:en-->How to create a custom feed in Django using the Syndication Feed Framework<!--:--><!--:it-->Creare un custom feed in Django con il Syndication Feed Framework<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/12/ruby-on-rails-and-jquery-multiselect-with-checkbox/" title="<!--:en-->Ruby on Rails and jQuery: multiselect with checkbox<!--:--><!--:it-->Ruby on Rails e jQuery: multiselect con checkbox<!--:-->"><!--:en-->Ruby on Rails and jQuery: multiselect with checkbox<!--:--><!--:it-->Ruby on Rails e jQuery: multiselect con checkbox<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/08/how-to-create-multiple-django-environments-using-virtualenv/" title="<!--:en-->How to create multiple Django environments using virtualenv<!--:--><!--:it-->Come creare multipli ambienti Django con virtualenv<!--:-->"><!--:en-->How to create multiple Django environments using virtualenv<!--:--><!--:it-->Come creare multipli ambienti Django con virtualenv<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/b-nDImINjHQ7SVhhWIsWGpx6TeU/0/da"><img src="http://feedads.g.doubleclick.net/~a/b-nDImINjHQ7SVhhWIsWGpx6TeU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/b-nDImINjHQ7SVhhWIsWGpx6TeU/1/da"><img src="http://feedads.g.doubleclick.net/~a/b-nDImINjHQ7SVhhWIsWGpx6TeU/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=9e0r_GedIfI:HBhF00xNvJc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=9e0r_GedIfI:HBhF00xNvJc:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=9e0r_GedIfI:HBhF00xNvJc:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=9e0r_GedIfI:HBhF00xNvJc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=9e0r_GedIfI:HBhF00xNvJc:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/9e0r_GedIfI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/</feedburner:origLink></item>
		<item>
		<title>Ruby Enumerables: Operation on hashes</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/F_UycOIol3E/</link>
		<comments>http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 10:42:48 +0000</pubDate>
		<dc:creator>Claudio</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=994</guid>
		<description><![CDATA[In my last post I talked about Ruby&#8217;s hash.
Today I will resume and complete the argument by describing some of the things you can do to manipulate the hash values.
1. How to iterate over Hash elements
The Ruby Hash class provides three different iterators: each, each_key, each_value.
There is actually a fourth iterator, each_pair but it is [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post I talked about <a title="Ruby Enumerables: Hashes" href="http://blog.devinterface.com/2011/01/ruby-enumerables-hashes/">Ruby&#8217;s hash</a>.<br />
Today I will resume and complete the argument by describing some of the things you can do to manipulate the hash values.</p>
<p><strong>1. How to iterate over Hash elements</strong></p>
<p>The Ruby Hash class provides three different iterators: <em>each</em>, <em>each_key</em>, <em>each_value</em>.<br />
There is actually a fourth iterator, <em>each_pair</em> but it is only an alias of <em>each</em>.</p>
<p>As you can expect the <em>each</em> iterator works as follows:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;company&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;DevInterface&quot;</span>, <span style="color:#996600;">&quot;activity&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Web Agency&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>key, val<span style="color:#006600; font-weight:bold;">|</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> key, <span style="color:#996600;">&quot;: &quot;</span>, val<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#008000; font-style:italic;"># Will print</span><br />
<span style="color:#996600;">&quot;company: DevInterface&quot;</span><br />
<span style="color:#996600;">&quot;activity: Web Agency&quot;</span></div></td></tr></tbody></table></div>
<p>The other two operators, respectively, allow to iterate only on the keys or only on the values of the hash.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;name&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Claudio&quot;</span>, <span style="color:#996600;">&quot;role&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Web Developer&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each_key</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>key<span style="color:#006600; font-weight:bold;">|</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> key<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#008000; font-style:italic;"># Will print</span><br />
<span style="color:#996600;">&quot;name&quot;</span><br />
<span style="color:#996600;">&quot;role&quot;</span><br />
<br />
<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;name&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Claudio&quot;</span>, <span style="color:#996600;">&quot;role&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Web Developer&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each_value</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>val<span style="color:#006600; font-weight:bold;">|</span><br />
<span style="color:#CC0066; font-weight:bold;">p</span> val<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#008000; font-style:italic;"># Will print</span><br />
<span style="color:#996600;">&quot;Claudio&quot;</span><br />
<span style="color:#996600;">&quot;Web Developer&quot;</span></div></td></tr></tbody></table></div>
<p><strong>2. How to invert the values with the keys</strong></p>
<p>An operation that can be in some cases very useful it&#8217;s the inversion of values with keys.<br />
The classic example is the phone book.</p>
<p>Suppose we have an hash that contains the telephone book as follows</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">phone_numbers = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;DevInterface&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;339-045-2223836&quot;</span>, <span style="color:#996600;">&quot;John&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;555-6677&quot;</span>, <span style="color:#996600;">&quot;Stefano&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;335-12345678&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>and we want to know who owns the number &#8220;555-6677&#8243;.<br />
We can iterate over all the hash to find the searched value and then return the key. But what if the hash contains 1000 elements instead of 3?</p>
<p>The alternative is to reverse the hash so numbers become the keys and names become values.</p>
<p>The Hash class provides the <em>invert</em> method for this purpose:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">inverted_phone_numbers = phone_numbers.<span style="color:#9900CC;">invert</span><br />
inverted_phone_numbers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;555-6677&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> &nbsp;<span style="color:#008000; font-style:italic;"># Will return &quot;John&quot;</span></div></td></tr></tbody></table></div>
<p>Before using the <em>invert</em> method, however, it&#8217;s fundamental keep in mind that the hash keys are unique, but the values can be duplicated.<br />
Consequently, when reversing a hash any duplicate values will be converted into a unique key, with consequent data loss .<br />
In fact, it&#8217;s not predictable which of the values will be kept and which will instead be discarded.</p>
<p>Using the example of the phone book if we had:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">phone_numbers = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;DevInterface&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;339-045-2223836&quot;</span>, <span style="color:#996600;">&quot;John&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;555-6677&quot;</span>, <span style="color:#996600;">&quot;Mary&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;555-6677&quot;</span>, <span style="color:#996600;">&quot;Stefano&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;335-12345678&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>and then perform the same operation as before</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">inverted_phone_numbers = phone_numbers.<span style="color:#9900CC;">invert</span><br />
inverted_phone_numbers<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;555-6677&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> &nbsp;<span style="color:#008000; font-style:italic;"># Will return &quot;John&quot; or &quot;Mary&quot;</span></div></td></tr></tbody></table></div>
<p>we can not know for sure if it will return &#8220;John&#8221; or &#8220;Mary&#8221;.</p>
<p><strong>3. How to convert a hash into an array</strong></p>
<p>You can convert a hash into an array using the method <em>to_a</em>.<br />
The result is an array where the even elements are the keys and the odd elements are the values.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">my_hash = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;a&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#996600;">&quot;b&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span>, <span style="color:#996600;">&quot;c&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
my_hash.<span style="color:#9900CC;">to_a</span> &nbsp; <span style="color:#008000; font-style:italic;"># [&quot;a&quot;, 1, &quot;b&quot;, 2, &quot;c&quot;, 3]</span></div></td></tr></tbody></table></div>
<p>But sometimes it is more convenient to have two separate array for keys and values. It &#8216;can get you in the following way:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">my_hash.<span style="color:#9900CC;">keys</span>.<span style="color:#9900CC;">to_a</span> &nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># [&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]</span><br />
my_hash.<span style="color:#9900CC;">values</span>.<span style="color:#9900CC;">to_a</span> &nbsp; <span style="color:#008000; font-style:italic;"># [1, 2, 3]</span></div></td></tr></tbody></table></div>
<p>Finally, using the <em>values_at</em> method, the hash can be extracted in an array selectively: you can select which elements to extract by passing keys to the method.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">my_hash.<span style="color:#9900CC;">values_at</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;a&quot;</span>, <span style="color:#996600;">&quot;c&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; <span style="color:#008000; font-style:italic;"># [1, 3]</span></div></td></tr></tbody></table></div>
<p>Ruby also allows the reverse conversion, create a hash from an array:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">my_array = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">4</span>, <span style="color:#006666;">5</span>, <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span><br />
my_hash = <span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">*</span>my_array<span style="color:#006600; font-weight:bold;">&#93;</span> &nbsp; <span style="color:#008000; font-style:italic;"># {1 &nbsp;=&gt; 2, 3 &nbsp;=&gt; 4, 5 &nbsp;=&gt; 6}</span></div></td></tr></tbody></table></div>
<p>Obviously, this conversion is only possible if the array has an even number of elements.</p>
<p><strong>4. How to sort an Hash</strong></p>
<p>A hash, as seen in <a title="Ruby Enumerables: Hashes" href="http://blog.devinterface.com/2011/01/ruby-enumerables-hashes/">previous posts</a>, is an un-ordered structure.<br />
However, in some cases it may be needed to order the values. There is therefore a <em>sort</em> method. But the result of this sorting is an array.<br />
This is because Ruby, to order a hash converts it into an array of arrays and then sorts it.</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">beatles = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;Jonn&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Lennon&quot;</span>, <span style="color:#996600;">&quot;Ringo&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Starr&quot;</span>, <span style="color:#996600;">&quot;Paul&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;McCartney&quot;</span>, <span style="color:#996600;">&quot;George&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Harrison&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
beatles.<span style="color:#9900CC;">sort</span> &nbsp;<span style="color:#008000; font-style:italic;"># &nbsp;[[&quot;George&quot;, &quot;Harrison&quot;], [&quot;Jonn&quot;, &quot;Lennon&quot;], [&quot;Paul&quot;, &quot;McCartney&quot;], [&quot;Ringo&quot;, &quot;Starr&quot;]]</span></div></td></tr></tbody></table></div>
<p><strong>5. How to merge two hashes</strong></p>
<p>The last topic I want to discuss today is how to merge two hashes.</p>
<p>Suppose we want to make an unlikely merging of two historical groups, the Beatles and the Rolling Stones:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">beatles = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;Jonn&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Lennon&quot;</span>, <span style="color:#996600;">&quot;Ringo&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Starr&quot;</span>, <span style="color:#996600;">&quot;Paul&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;McCartney&quot;</span>, <span style="color:#996600;">&quot;George&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Harrison&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
rolling_stones = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;Mick&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Jagger&quot;</span>, <span style="color:#996600;">&quot;Keith&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Richards&quot;</span>, <span style="color:#996600;">&quot;Ronnie&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Wood&quot;</span>, <span style="color:#996600;">&quot;Charlie&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Watts&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
rolling_beatles = beatles.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>rolling_stones<span style="color:#006600; font-weight:bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>The result is a third hash composed as follows:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">p</span> rolling_beatles<br />
<span style="color:#008000; font-style:italic;"># {&quot;Jonn&quot; &nbsp;=&gt; &quot;Lennon&quot;, &quot;Ringo&quot; =&gt; &quot;Starr&quot;, &quot;Paul&quot; &nbsp;=&gt; &quot;McCartney&quot;, &quot;George&quot; &nbsp;=&gt; &quot;Harrison&quot;,</span><br />
<span style="color:#996600;">&quot;Mick&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Jagger&quot;</span>, <span style="color:#996600;">&quot;Keith&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Richards&quot;</span>, <span style="color:#996600;">&quot;Ronnie&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Wood&quot;</span>, <span style="color:#996600;">&quot;Charlie&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;Watts&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>In the case of duplicate keys, however, the merge only keeps the key of the second hash:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;a&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#996600;">&quot;b&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span>, <span style="color:#996600;">&quot;c&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
b = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;a&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span>, <span style="color:#996600;">&quot;d&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>, <span style="color:#996600;">&quot;e&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#125;</span></div></td></tr></tbody></table></div>
<p>c = a.merge(b)  # {&#8220;a&#8221;  => 5, &#8220;b&#8221;  => 2, &#8220;c&#8221;  => 3, &#8220;d&#8221;  => 7, &#8220;e&#8221;  => 9}</p>
<p>Alternatively, you can pass to the <em>merge</em> method a block of code to handle conflicts on the keys:</p>
<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">a = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;a&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#996600;">&quot;b&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span>, <span style="color:#996600;">&quot;c&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
b = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#996600;">&quot;a&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span>, <span style="color:#996600;">&quot;d&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">7</span>, <span style="color:#996600;">&quot;e&quot;</span> &nbsp;<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#125;</span><br />
<br />
c = a.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>b<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>key, old_val, new_val<span style="color:#006600; font-weight:bold;">|</span> old_val <span style="color:#006600; font-weight:bold;">&lt;</span> new_val ? old_val : new_val<span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#008000; font-style:italic;"># {&quot;a&quot; &nbsp;=&gt; 1, &quot;b&quot; &nbsp;=&gt; 2, &quot;c&quot; &nbsp;=&gt; 3, &quot;d&quot; &nbsp;=&gt; 7, &quot;e&quot; &nbsp;=&gt; 9}</span></div></td></tr></tbody></table></div>
<p>As you can see the result of this merge is different from the above depending on the condition specified in the code block.<!-- Social Bookmarking Reloaded BEGIN -->
<div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'Ruby Enumerables: Operation on hashes' to Del.icio.us" alt="Add 'Ruby Enumerables: Operation on hashes' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'Ruby Enumerables: Operation on hashes' to digg" alt="Add 'Ruby Enumerables: Operation on hashes' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'Ruby Enumerables: Operation on hashes' to reddit" alt="Add 'Ruby Enumerables: Operation on hashes' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="Add 'Ruby Enumerables: Operation on hashes' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'Ruby Enumerables: Operation on hashes' to Technorati" alt="Add 'Ruby Enumerables: Operation on hashes' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'Ruby Enumerables: Operation on hashes' to Stumble Upon" alt="Add 'Ruby Enumerables: Operation on hashes' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'Ruby Enumerables: Operation on hashes' to Google Bookmarks" alt="Add 'Ruby Enumerables: Operation on hashes' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="Add 'Ruby Enumerables: Operation on hashes' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'Ruby Enumerables: Operation on hashes' to Rojo" alt="Add 'Ruby Enumerables: Operation on hashes' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'Ruby Enumerables: Operation on hashes' to OKnotizie" alt="Add 'Ruby Enumerables: Operation on hashes' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=Ruby+Enumerables%3A+Operation+on+hashes&amp;url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="Add 'Ruby Enumerables: Operation on hashes' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'Ruby Enumerables: Operation on hashes' to Diggita" alt="Add 'Ruby Enumerables: Operation on hashes' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;t=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'Ruby Enumerables: Operation on hashes' to FaceBook" alt="Add 'Ruby Enumerables: Operation on hashes' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes" title="Add 'Ruby Enumerables: Operation on hashes' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'Ruby Enumerables: Operation on hashes' to Upnews" alt="Add 'Ruby Enumerables: Operation on hashes' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="Add 'Ruby Enumerables: Operation on hashes' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'Ruby Enumerables: Operation on hashes' to Twitter" alt="Add 'Ruby Enumerables: Operation on hashes' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=Ruby+Enumerables%3A+Operation+on+hashes&amp;url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="Add 'Ruby Enumerables: Operation on hashes' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'Ruby Enumerables: Operation on hashes' to Technotizie" alt="Add 'Ruby Enumerables: Operation on hashes' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=Ruby+Enumerables%3A+Operation+on+hashes&amp;url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="Add 'Ruby Enumerables: Operation on hashes' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'Ruby Enumerables: Operation on hashes' to FriendFeed" alt="Add 'Ruby Enumerables: Operation on hashes' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/&amp;title=Ruby+Enumerables%3A+Operation+on+hashes&amp;srcURL=http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/" title="Add 'Ruby Enumerables: Operation on hashes' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'Ruby Enumerables: Operation on hashes' to Google Buzz" alt="Add 'Ruby Enumerables: Operation on hashes' to Google Buzz" /></a></div>
<p><!-- Social Bookmarking Reloaded END --></p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/01/ruby-enumerables-hashes/" title="<!--:en-->Ruby Enumerables: Hashes<!--:--><!--:it-->Ruby Enumerables: Hashes<!--:-->"><!--:en-->Ruby Enumerables: Hashes<!--:--><!--:it-->Ruby Enumerables: Hashes<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/08/tips-multiple-pagination-with-will_paginate/" title="<!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:-->"><!--:en-->Tips: Multiple pagination with will_paginate<!--:--><!--:it-->Tips: Paginazione multipla con will_paginate<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/05/two-step-signup-with-devise/" title="<!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:-->"><!--:en-->Two step signup with Devise<!--:--><!--:it-->Registrazione in due step con Devise<!--:--></a></li><li><a href="http://blog.devinterface.com/2011/04/prevent-registration-of-reserved-login/" title="<!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:-->"><!--:en-->Prevent registration of reserved login<!--:--><!--:it-->Prevenire la registrazione di login riservate <!--:--></a></li><li><a href="http://blog.devinterface.com/2010/07/design-patterns-in-ruby-chain-of-responsibility/" title="<!--:en-->Design Patterns in Ruby: Chain of Responsibility<!--:--><!--:it-->Design Patterns in Ruby: Chain of Responsibility<!--:-->"><!--:en-->Design Patterns in Ruby: Chain of Responsibility<!--:--><!--:it-->Design Patterns in Ruby: Chain of Responsibility<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/UbLe5K48JHfbNjAtogi0qJvWFSM/0/da"><img src="http://feedads.g.doubleclick.net/~a/UbLe5K48JHfbNjAtogi0qJvWFSM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/UbLe5K48JHfbNjAtogi0qJvWFSM/1/da"><img src="http://feedads.g.doubleclick.net/~a/UbLe5K48JHfbNjAtogi0qJvWFSM/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=F_UycOIol3E:u4lQBJHE7go:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=F_UycOIol3E:u4lQBJHE7go:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=F_UycOIol3E:u4lQBJHE7go:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=F_UycOIol3E:u4lQBJHE7go:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=F_UycOIol3E:u4lQBJHE7go:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/F_UycOIol3E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/02/ruby-enumerables-operation-on-hashes/</feedburner:origLink></item>
		<item>
		<title>How to create a custom feed in Django using the Syndication Feed Framework</title>
		<link>http://feedproxy.google.com/~r/devinterfaceblog/~3/yBbGRidJPG0/</link>
		<comments>http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 14:28:23 +0000</pubDate>
		<dc:creator>Stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.devinterface.com/?p=982</guid>
		<description><![CDATA[Hello everyone.

In this article I will show you how to create a custom feed in Django, using the Django Syndication Feed Framework 1.2 or higher.

I&#8217;ve had to create an XML with some more tags for each item in the feed. 
In particular, in addition to the usual tags present in an RSS feed, I&#8217;ve added [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone.</p>

<p>In this article I will show you how to create a custom feed in Django, using the Django Syndication Feed Framework 1.2 or higher.</p>

<p>I&#8217;ve had to create an <span class="caps">XML </span>with some more tags for each item in the feed. <br />
In particular, in addition to the usual tags present in an <span class="caps">RSS </span>feed, I&#8217;ve added the </p>

<pre>&lt;short_description/&gt; </pre>

<p> and </p>

<pre>&lt;image/&gt;</pre>

<p> tags.</p>

<p>Reading the official documentation of the framework, it is recommended to create a <a href="http://docs.djangoproject.com/en/dev/ref/contrib/syndication/#custom-feed-generators">custom feed generator</a>, but the process is not very clear.</p>

<p>Let&#8217;s see step by step how to fix everything.</p>

<p>First we create a custom feed generator.</p>

<p>This generator must create the same <span class="caps">XML </span>that would produce the framework&#8217;s default generator and for each item in the list it will add the new tags.</p>

<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> CustomFeedGenerator<span style="color: black;">&#40;</span>Rss201rev2Feed<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> add_item_elements<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> handler<span style="color: #66cc66;">,</span> item<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">super</span><span style="color: black;">&#40;</span>CustomFeedGenerator<span style="color: #66cc66;">,</span> <span style="color: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">add_item_elements</span><span style="color: black;">&#40;</span>handler<span style="color: #66cc66;">,</span> item<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; handler.<span style="color: black;">addQuickElement</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;image&quot;</span><span style="color: #66cc66;">,</span> item<span style="color: black;">&#91;</span><span style="color: #483d8b;">'image'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; handler.<span style="color: black;">addQuickElement</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">&quot;short_description&quot;</span><span style="color: #66cc66;">,</span> item<span style="color: black;">&#91;</span><span style="color: #483d8b;">'short_description'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></div></td></tr></tbody></table></div>

<p>We see that the generator calls the method <i>add_item_elements(handler, item)</i> of its superclass and then adds new <span class="caps">XML </span>tags for each item.<br />
Note that the values that will be inserted in the <i>image</i> and <i>short_description</i> tags must be present in the <i>item</i> dictionary passed as argument.</p>

<p>So let&#8217;s create our <i>CustomFeed</i> class that inherits from <i>Feed</i> class and see how to tell it to use the <i>CustomFeedGenerator</i> and how to insert the new values in the <i>item</i> dictionary.</p>

<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:450px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">class</span> CustomFeed<span style="color: black;">&#40;</span>Feed<span style="color: black;">&#41;</span>:<br />
<br />
&nbsp; &nbsp; feed_type <span style="color: #66cc66;">=</span> CustomFeedGenerator<br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> title<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> u<span style="color: #483d8b;">&quot;My amazing feed&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> description<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> u<span style="color: #483d8b;">&quot;My feed description&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> link<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #483d8b;">&quot;http://%s&quot;</span> % obj.<span style="color: black;">get_absolute_url</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">def</span> item_extra_kwargs<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> obj<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">&quot;&quot;&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns an extra keyword arguments dictionary that is used with<br />
&nbsp; &nbsp; &nbsp; &nbsp; the `add_item` call of the feed generator.<br />
&nbsp; &nbsp; &nbsp; &nbsp; Add the 'content' field of the 'Entry' item, to be used by the custom feed generator.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &quot;&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span> <span style="color: #483d8b;">'image'</span>: obj.<span style="color: black;">get_picture</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">get_medium_url</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">if</span> obj.<span style="color: black;">get_picture</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">else</span> <span style="color: #483d8b;">&quot;&quot;</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #483d8b;">'short_description'</span> : obj.<span style="color: black;">get_preview</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: black;">&#125;</span></div></td></tr></tbody></table></div>

<p><i>CustomFeed</i> is very similar to the various feeds that we are accustomed. The only difference is represented by the statement of the type of feed</p>


<pre>feed_type = CustomFeedGenerator</pre>


<p>and by the method</p>


<pre>item_extra_kwargs</pre>

 able to append any new values in the <i>item</i> dictionary, obtaining the desired result.<!-- Social Bookmarking Reloaded BEGIN --><div class="social_bookmark"><em>Share on:</em><br /><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Del.icio.us"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/delicious.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Del.icio.us" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Del.icio.us" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to digg"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/digg.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to digg" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to digg" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to reddit"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/reddit.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to reddit" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to reddit" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Technorati"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technorati.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Technorati" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Technorati" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Stumble Upon"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/stumbleupon.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Stumble Upon" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Stumble Upon" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Google Bookmarks"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/google.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Google Bookmarks" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Google Bookmarks" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.rojo.com/add-subscription/?resource=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Rojo"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/rojo.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Rojo" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Rojo" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://oknotizie.alice.it/post?url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to OKnotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/oknotizie.gif" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to OKnotizie" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to OKnotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.diggita.it/submit.php?title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework&amp;url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Diggita"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/diggita.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Diggita" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Diggita" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/share.php?u=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;t=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to FaceBook"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/facebook.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to FaceBook" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to FaceBook" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.upnews.it/submit?url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Upnews"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/upnews.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Upnews" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Upnews" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home?status=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Twitter"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/twitter.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Twitter" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Twitter" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technotizie.it/posta_ok?action=f2&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework&amp;url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Technotizie"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/technotizie.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Technotizie" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Technotizie" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://friendfeed.com/share/bookmarklet/frame#title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework&amp;url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to FriendFeed"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/friendfeed.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to FriendFeed" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to FriendFeed" /></a><a class="social_img" onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,border=0,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/reader/link?url=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/&amp;title=How+to+create+a+custom+feed+in+Django+using+the+Syndication+Feed+Framework&amp;srcURL=http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Google Buzz"><img src="http://blog.devinterface.com/wp-content/plugins/social-bookmarking-reloaded/googlebuzz.png" title="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Google Buzz" alt="Add 'How to create a custom feed in Django using the Syndication Feed Framework' to Google Buzz" /></a></div>
<!-- Social Bookmarking Reloaded END --><h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://blog.devinterface.com/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/" title="<!--:en-->How to implement two dropdowns dependent on each other using Django and jQuery<!--:--><!--:it-->Come implementare due dropdown dipendenti l&#8217;una dall&#8217;altra in Django e jQuery<!--:-->"><!--:en-->How to implement two dropdowns dependent on each other using Django and jQuery<!--:--><!--:it-->Come implementare due dropdown dipendenti l&#8217;una dall&#8217;altra in Django e jQuery<!--:--></a></li><li><a href="http://blog.devinterface.com/2010/08/how-to-create-multiple-django-environments-using-virtualenv/" title="<!--:en-->How to create multiple Django environments using virtualenv<!--:--><!--:it-->Come creare multipli ambienti Django con virtualenv<!--:-->"><!--:en-->How to create multiple Django environments using virtualenv<!--:--><!--:it-->Come creare multipli ambienti Django con virtualenv<!--:--></a></li><li><a href="http://blog.devinterface.com/2009/10/linq-serialize-classes/" title="<!--:en-->LINQ: serialize C# classes <!--:--><!--:it-->LINQ: serializzare classi C#<!--:-->"><!--:en-->LINQ: serialize C# classes <!--:--><!--:it-->LINQ: serializzare classi C#<!--:--></a></li></ul>
<p><a href="http://feedads.g.doubleclick.net/~a/i7ZxrfKlTYV7YakMPcDEzIEz_Xw/0/da"><img src="http://feedads.g.doubleclick.net/~a/i7ZxrfKlTYV7YakMPcDEzIEz_Xw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/i7ZxrfKlTYV7YakMPcDEzIEz_Xw/1/da"><img src="http://feedads.g.doubleclick.net/~a/i7ZxrfKlTYV7YakMPcDEzIEz_Xw/1/di" border="0" ismap="true"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=yBbGRidJPG0:-O9kq0h88xg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=yBbGRidJPG0:-O9kq0h88xg:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=yBbGRidJPG0:-O9kq0h88xg:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/devinterfaceblog?a=yBbGRidJPG0:-O9kq0h88xg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/devinterfaceblog?i=yBbGRidJPG0:-O9kq0h88xg:D7DqB2pKExk" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/devinterfaceblog/~4/yBbGRidJPG0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/</feedburner:origLink></item>
	</channel>
</rss>

