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

<channel>
	<title>XP on Rails</title>
	<atom:link href="http://xponrails.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://xponrails.net</link>
	<description>Extreme Programming Blog</description>
	<lastBuildDate>Fri, 04 Mar 2011 14:49:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to send email asynchronously using Devise and Rails3</title>
		<link>http://xponrails.net/2011/03/04/how-to-send-email-asynchronously-using-devise-and-rails3/</link>
		<comments>http://xponrails.net/2011/03/04/how-to-send-email-asynchronously-using-devise-and-rails3/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 14:49:31 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[delayed_job]]></category>
		<category><![CDATA[devise]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=154</guid>
		<description><![CDATA[ORIGINAL POST

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):

#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; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.devinterface.com/2011/03/how-to-send-email-asynchronously-using-devise-and-rails3/"><span class="caps">ORIGINAL POST</span></a></p>

<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">Devise</a> and <a href="https://github.com/collectiveidea/delayed_job/tree/v3.0">delayed_job</a> correctly installed.</p>

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

<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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></div>

<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>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">User<span style="color: #666666; font-style: italic;">#send_confirmation_instructions_without_delay failed with NoMethodError: undefined method 'send_confirmation_instructions_without_delay' for #&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></div>

<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;e methods using the syntax specified by intridea to send emails in the background:</p>

<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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></div>

<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>

<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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></div>

<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!</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fxponrails.net%2F2011%2F03%2F04%2Fhow-to-send-email-asynchronously-using-devise-and-rails3%2F&amp;linkname=How%20to%20send%20email%20asynchronously%20using%20Devise%20and%20Rails3">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://xponrails.net/2011/03/04/how-to-send-email-asynchronously-using-devise-and-rails3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to implement two dropdowns dependent on each other using Django and jQuery</title>
		<link>http://xponrails.net/2011/02/25/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/</link>
		<comments>http://xponrails.net/2011/02/25/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 15:42:50 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=150</guid>
		<description><![CDATA[ORIGINAL POST

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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.devinterface.com/it/2011/02/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/"><span class="caps">ORIGINAL POST</span></a></p>

<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:435px;"><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 = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=100<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #dc143c;">code</span> = models.<span style="color: black;">SlugField</span><span style="color: black;">&#40;</span>primary_key=<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 = models.<span style="color: black;">CharField</span><span style="color: black;">&#40;</span>max_length=100<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #dc143c;">code</span> = models.<span style="color: black;">SlugField</span><span style="color: black;">&#40;</span>primary_key=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; brand = models.<span style="color: black;">ForeignKey</span><span style="color: black;">&#40;</span>VehicleBrand<span style="color: black;">&#41;</span></div></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:435px;"><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 = template.<span style="color: black;">Library</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
@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 = 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></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:435px;"><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></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:435px;"><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, brand<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; current_brand = 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>=brand<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; models = 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=current_brand<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; json_models = serializers.<span style="color: black;">serialize</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;json&quot;</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, mimetype=<span style="color: #483d8b;">&quot;application/javascript&quot;</span><span style="color: black;">&#41;</span></div></div>

<p>and in urls.py:</p>

<div class="codecolorer-container python vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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: #483d8b;">'all_json_models'</span><span style="color: black;">&#41;</span>,</div></div>

<p>Finally, the javascript method myAwesomeFunctionToCallWhenAModelIsSelected() will be invoked when a model will be selected.</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fxponrails.net%2F2011%2F02%2F25%2Fhow-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery%2F&amp;linkname=How%20to%20implement%20two%20dropdowns%20dependent%20on%20each%20other%20using%20Django%20and%20jQuery">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://xponrails.net/2011/02/25/how-to-implement-two-dropdowns-dependent-on-each-other-using-django-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create a custom feed in Django using the Syndication Feed Framework</title>
		<link>http://xponrails.net/2011/01/31/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/</link>
		<comments>http://xponrails.net/2011/01/31/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 14:30:39 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[feed]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=146</guid>
		<description><![CDATA[ORIGINAL POST

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 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.devinterface.com/2011/01/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/"><span class="caps">ORIGINAL POST</span></a></p>

<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:435px;"><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>, handler, 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: #008000;">self</span><span style="color: black;">&#41;</span>.<span style="color: black;">add_item_elements</span><span style="color: black;">&#40;</span>handler, 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>, 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>, 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></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:435px;"><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 = 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>, 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>, 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>, 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> <span style="color: #66cc66;">%</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>, 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>,<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: black;">&#125;</span></div></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>

<p> able to append any new values in the <i>item</i> dictionary, obtaining the desired result.</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fxponrails.net%2F2011%2F01%2F31%2Fhow-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework%2F&amp;linkname=How%20to%20create%20a%20custom%20feed%20in%20Django%20using%20the%20Syndication%20Feed%20Framework">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://xponrails.net/2011/01/31/how-to-create-a-custom-feed-in-django-using-the-syndication-feed-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install PostgreSQL and psycopg2 on Osx Snow Leopard</title>
		<link>http://xponrails.net/2010/10/06/how-to-install-postgresql-and-psycopg2-on-osx-snow-leopard/</link>
		<comments>http://xponrails.net/2010/10/06/how-to-install-postgresql-and-psycopg2-on-osx-snow-leopard/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 18:33:15 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[postgreSQL]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=143</guid>
		<description><![CDATA[ORIGINAL POST

Hello everyone.

In my last post I showed how to install MySQL from source on Osx.
Among the many comments received, some of them suggested me to use homebrew

I recommend everyone to use this tool in order to easily install several unix packages on OSX.

Among the packages that can be installed there&#8217;s also PostgreSQL, the subject [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.devinterface.com/2010/10/how-to-install-postgresql-and-psycopg2-on-osx-snow-leopard/"><span class="caps">ORIGINAL POST</span></a></p>

<p>Hello everyone.</p>

<p>In my last <a href="http://blog.devinterface.com/2010/09/how-to-install-mysql-and-rails-on-osx-snow-leopard/">post</a> I showed how to install MySQL from source on Osx.<br />
Among the many comments received, some of them suggested me to use <a href="http://github.com/mxcl/homebrew">homebrew</a></p>

<p>I recommend everyone to use this tool in order to easily install several unix packages on <span class="caps">OSX.</span></p>

<p>Among the packages that can be installed there&#8217;s also PostgreSQL, the subject of today&#8217;s post.</p>

<p>If you install PostgreSQL via homebrew, maybe have a look at this <a href="http://blog.clearto.me/2010/04/29/postgresql_on_snow_leopard_with_rails_using_homebrew.html">post</a></p>

<p>This post is instead directed to those who are willing to install the database from source in /usr/local/postgresql-8.4.4</p>

<h1>Step 1: Set the $PATH environment variable</h1>

<p>Open a terminal and set the $PATH environment variable in order to link the correct folders in /usr/local/</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mate ~<span style="color: #000000; font-weight: bold;">/</span>.profile</div></div>

<p>Add, if it does not exist, this line at the bottom of the .profile file:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;~/bin;/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/pgsql/bin:<span style="color: #007800;">$PATH</span>&quot;</span></div></div>

<p>and reload the $PATH in this way:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.profile</div></div>

<p>To verify that our $PATH contains the paths set above, type the following command:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PATH</span></div></div>

<h1>Step 2: Download PostgreSQL</h1>

<p>Create a new folder to download the sources and compile them:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src</div></div>

<p>Download the latest version available at the time of writing this tutorial:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>ftp2.it.postgresql.org<span style="color: #000000; font-weight: bold;">/</span>mirrors<span style="color: #000000; font-weight: bold;">/</span>postgres<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>v8.4.4<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.4.tar.gz</div></div>

<h1>Step 3: Compile and Install</h1>

<p>Build and install PostgreSQL with the following commands:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-zvxf</span> postgresql-8.4.4.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> postgresql-8.4.4.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> postgresql-8.4.4<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.4<br />
<span style="color: #007800;">ARCH</span>=x86_64 <span style="color: #007800;">CFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> <span style="color: #007800;">LDFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> <span style="color: #c20cb9; font-weight: bold;">make</span><br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>

<p>Create a symbilic link, used before in the $PATH</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.4 <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span></div></div>

<p>Create now a postgres user, owner of the server:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres<br />
dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres PrimaryGroupID 0<br />
dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres UniqueID 75<br />
dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres UserShell <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span><br />
dscl localhost <span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres<br />
dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres NFSHomeDirectory <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>postgres<br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>postgres<br />
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-Rf</span> postgres:postgres <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>postgres<br />
dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>postgres<br />
dscl localhost create <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>postgres UniqueID <span style="color: #000000;">75</span><br />
dscl localhost append <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>postgres GroupMembership postgres</div></div>

<p>And let&#8217;s give him read permissions over the installation directory:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> postgres <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>postgresql-8.4.4<span style="color: #000000; font-weight: bold;">/</span></div></div>

<p>In a new console, log in as postgres and start the server:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">su</span> - postgres<br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>initdb <span style="color: #660033;">-E</span> UTF8 <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_ctl <span style="color: #660033;">-D</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>data<span style="color: #000000; font-weight: bold;">/</span>postgresql.log start</div></div>

<p>If the server is started correctly, we can create our test database:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">createdb <span style="color: #7a0874; font-weight: bold;">test</span><br />
psql <span style="color: #7a0874; font-weight: bold;">test</span></div></div>

<p>Now delete unnecessary folders created when creating the user:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span><br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>home<br />
dscl localhost delete <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres NFSHomeDirectory<br />
dscl localhost <span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #000000; font-weight: bold;">/</span>Local<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>postgres<br />
<span style="color: #7a0874; font-weight: bold;">exit</span></div></div>

<p>Then we can create scripts to start and stop the PostgreSQL server using the command line.</p>

<p>We create a bin folder in our home and the following file, also giving execute permissions:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> bin<br />
<span style="color: #c20cb9; font-weight: bold;">touch</span> pgsqlscript<br />
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x pgsqlscript</div></div>

<p>Edit the file you&#8217;ve just created by inserting the following body:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting PostgreSQL server&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> postgres <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsql/data/postgresql.log start'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping PostgreSQL server&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span> postgres <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ stop'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; &nbsp; start<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; start<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; stop<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stop<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; restart<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stop<br />
&nbsp; &nbsp; &nbsp; &nbsp; start<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: {start|stop|restart}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span></div></div>

<p>At this point you can start the server by typing &#8220;pgsqlscript start&#8221; in the console. To stop the server just type &#8220;pgsqlscript stop&#8221;.</p>

<h1>Step 4: Install Ruby PostgreSQL drivers</h1>

<p>Just install the pg gem to have access to the database.</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem <span style="color: #c20cb9; font-weight: bold;">install</span> pg</div></div>

<h1>Step 5: Install Python drivers for PostgreSQL</h1>

<p>Download the psycopg2 package</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<br />
curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>initd.org<span style="color: #000000; font-weight: bold;">/</span>psycopg<span style="color: #000000; font-weight: bold;">/</span>tarballs<span style="color: #000000; font-weight: bold;">/</span>psycopg2-2.2.2.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzfv psycopg2-2.2.2.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> psycopg2-2.2.2</div></div>

<p>and modify the setup.cfg file with this one:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">&#91;</span>build_ext<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #007800;">define</span>=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3<br />
<br />
<span style="color: #666666; font-style: italic;"># PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this)</span><br />
<span style="color: #666666; font-style: italic;"># PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)</span><br />
<span style="color: #666666; font-style: italic;"># HAVE_PQFREEMEM should be defined on PostgreSQL &gt;= 7.4</span><br />
<span style="color: #666666; font-style: italic;"># HAVE_PQPROTOCOL3 should be defined on PostgreSQL &gt;= 7.4</span><br />
<span style="color: #666666; font-style: italic;"># PSYCOPG_DEBUG can be added to enable verbose debug information</span><br />
<span style="color: #666666; font-style: italic;"># PSYCOPG_OWN_QUOTING can be added, but it is deprecated (will go away in 2.1)</span><br />
<span style="color: #666666; font-style: italic;"># PSYCOPG_NEW_BOOLEAN to format booleans as true/false vs 't'/'f'</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Set to 1 to use Python datatime objects for default date/time representation.</span><br />
<span style="color: #007800;">use_pydatetime</span>=<span style="color: #000000;">1</span><br />
<br />
<span style="color: #666666; font-style: italic;"># If the build system does not find the mx.DateTime headers, try</span><br />
<span style="color: #666666; font-style: italic;"># uncommenting the following line and setting its value to the right path.</span><br />
<span style="color: #666666; font-style: italic;">#mx_include_dir=</span><br />
<br />
<span style="color: #666666; font-style: italic;"># For Windows only:</span><br />
<span style="color: #666666; font-style: italic;"># Set to 1 if the PostgreSQL library was built with OpenSSL.</span><br />
<span style="color: #666666; font-style: italic;"># Required to link in OpenSSL libraries and dependencies.</span><br />
<span style="color: #007800;">have_ssl</span>=<span style="color: #000000;">0</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Statically link against the postgresql client library.</span><br />
<span style="color: #007800;">static_libpq</span>=<span style="color: #000000;">0</span><br />
<br />
<span style="color: #666666; font-style: italic;"># &quot;pg_config&quot; is the preferred method to locate PostgreSQL headers and</span><br />
<span style="color: #666666; font-style: italic;"># libraries needed to build psycopg2. If pg_config is not in the path or</span><br />
<span style="color: #666666; font-style: italic;"># is installed under a different name uncomment the following option and</span><br />
<span style="color: #666666; font-style: italic;"># set it to the pg_config full path.</span><br />
<span style="color: #007800;">pg_config</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pg_config<br />
<br />
<span style="color: #666666; font-style: italic;"># If &quot;pg_config&quot; is not available, &quot;include_dirs&quot; can be used to locate</span><br />
<span style="color: #666666; font-style: italic;"># postgresql headers and libraries. Some extra checks on sys.platform will</span><br />
<span style="color: #666666; font-style: italic;"># still be done in setup.py.</span><br />
<span style="color: #666666; font-style: italic;"># The next line is the default as used on psycopg author Debian laptop:</span><br />
<span style="color: #666666; font-style: italic;">#include_dirs=/usr/local/lib</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Uncomment next line on Mandrake 10.x (and comment previous ones):</span><br />
<span style="color: #666666; font-style: italic;">#include_dirs=/usr/include/pgsql/8.0:/usr/include/pgsql/8.0/server</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Uncomment next line on SUSE 9.3 (and comment previous ones):</span><br />
<span style="color: #666666; font-style: italic;">#include_dirs=/usr/include/pgsql:/usr/include/pgsql/server</span><br />
<br />
<span style="color: #666666; font-style: italic;"># If postgresql is installed somewhere weird (i.e., not in your runtime library</span><br />
<span style="color: #666666; font-style: italic;"># path like /usr/lib), just add the right path in &quot;library_dirs&quot; and any extra</span><br />
<span style="color: #666666; font-style: italic;"># libraries required to link in &quot;libraries&quot;.</span><br />
<span style="color: #007800;">library_dirs</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>pgsql<span style="color: #000000; font-weight: bold;">/</span>lib<br />
<span style="color: #007800;">libraries</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib</div></div>

<p>At this point we can compile and install the package:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></div></div><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fxponrails.net%2F2010%2F10%2F06%2Fhow-to-install-postgresql-and-psycopg2-on-osx-snow-leopard%2F&amp;linkname=How%20to%20install%20PostgreSQL%20and%20psycopg2%20on%20Osx%20Snow%20Leopard">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://xponrails.net/2010/10/06/how-to-install-postgresql-and-psycopg2-on-osx-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to install MySQL and Rails on Osx Snow Leopard</title>
		<link>http://xponrails.net/2010/09/13/how-to-install-mysql-and-rails-on-osx-snow-leopard/</link>
		<comments>http://xponrails.net/2010/09/13/how-to-install-mysql-and-rails-on-osx-snow-leopard/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 09:57:10 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[snow leopard]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=137</guid>
		<description><![CDATA[ORIGINAL POST

Hello everyone.

These days I&#8217;ve bought a MacBook Pro with Osx Snow Leopard 64-bit pre installed.

Having to develop mainly in Rails and Django on MySQL and PostgreSQL, I&#8217;ve found some difficulties to install and properly configure all packages.

The main problems were due to the presence of 32bit libraries and other at 64bit. For example, Python [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.devinterface.com/2010/09/how-to-install-mysql-and-rails-on-osx-snow-leopard/"><span class="caps">ORIGINAL POST</span></a></p>

<p>Hello everyone.</p>

<p>These days I&#8217;ve bought a MacBook Pro with Osx Snow Leopard 64-bit pre installed.</p>

<p>Having to develop mainly in Rails and Django on MySQL and PostgreSQL, I&#8217;ve found some difficulties to install and properly configure all packages.</p>

<p>The main problems were due to the presence of 32bit libraries and other at 64bit. For example, Python or Ruby (already installed by default) were compiled at 32bit. Everything seems to work best, however, until you try to install the gem &#8220;mysql&#8221; or the eggs &#8220;psycopg2&#8243; or &#8220;MySQL_python&#8221;.</p>

<p>These database drivers, having to be &#8220;compiled&#8221;, generate many problems of incompatibility between different architectures.</p>

<p>In this first tutorial, we&#8217;ll see how to install MySQL and Rails 3.0. In the next we&#8217;ll see how to proceed with Django and PostgreSQL.</p>

<p>The approaches taken by me are simply the result of googling and other online tutorials. So I&#8217;ll link every resource I&#8217;ve used.</p>

<p>Regarding the installation of MySQL, I&#8217;ve mainly followed the <a href="http://hivelogic.com/articles/compiling-mysql-on-snow-leopard">Hivelogic</a> tutorial.</p>

<p>See below the key points that allowed a successful installation.</p>

<h1>Step 1: Set the $PATH environment variable</h1>

<p>Open a terminal and set the $PATH environment variable in order to link the correct folders in /usr/local/</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mate ~<span style="color: #000000; font-weight: bold;">/</span>.profile</div></div>

<p>Add, if it does not exist, this line at the bottom of the .profile file:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;~/bin;/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:<span style="color: #007800;">$PATH</span>&quot;</span></div></div>

<p>and reload the $PATH in this way:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.profile</div></div>

<p>To verify that our $PATH contains the paths set above, type the following command:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PATH</span></div></div>

<h1>Step 2: Download MySQL</h1>

<p>Create a new folder to download the sources and compile them:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src</div></div>

<p>Download the latest version available at the time of writing this tutorial:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">curl <span style="color: #660033;">-O</span> http:<span style="color: #000000; font-weight: bold;">//</span>mysql.mirrors.pair.com<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>MySQL-<span style="color: #000000;">5.1</span><span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.47.tar.gz</div></div>

<h1>Step 3: Compile and Install</h1>

<p>Build and install MySQL with the following commands:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf mysql-5.1.47.tar.gz<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> mysql-5.1.47<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql <span style="color: #660033;">--with-extra-charsets</span>=complex \<br />
<span style="color: #660033;">--enable-thread-safe-client</span> <span style="color: #660033;">--enable-local-infile</span> <span style="color: #660033;">--enable-shared</span> \<br />
<span style="color: #660033;">--with-plugins</span>=innobase<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>

<p>At this point we create a mysql user and a default database.</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> .<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_install_db <span style="color: #660033;">--user</span>=mysql<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> mysql .<span style="color: #000000; font-weight: bold;">/</span>var<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ..</div></div>

<p>Then we can create scripts to start and stop the MySQL server using the command line.</p>

<p>We create a bin folder in our home and the following file, also giving execute permissions:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> bin<br />
<span style="color: #c20cb9; font-weight: bold;">touch</span> mysqlscript<br />
<span style="color: #c20cb9; font-weight: bold;">chmod</span> +x mysqlscript</div></div>

<p>Edit the file you&#8217;ve just created by inserting the following body:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
start<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Starting MysSQL server&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql ; <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqld_safe &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
stop<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <br />
<span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Stopping MySQL server&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql ; <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqladmin <span style="color: #660033;">-u</span> root <span style="color: #660033;">-p</span> shutdown<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; &nbsp; start<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; start<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; stop<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stop<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; restart<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; stop<br />
&nbsp; &nbsp; &nbsp; &nbsp; start<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Usage: {start|stop|restart}&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$?</span></div></div>

<p>At this point you can start the server by typing &#8220;mysqlsript start&#8221; in the console. To stop the server just type &#8220;mysqlscript stop&#8221;.</p>

<p>We are now able to install Ruby on Rails. As mentioned at the beginning of the article, system Ruby is compiled at 32bit.<br />
If you want to compile from source at 64bit and place it in /usr/local/ ruby just follow this <a href="http://hivelogic.com/articles/compiling-ruby-rubygems-and-rails-on-snow-leopard">tutorial</a>.</p>

<p>Since it is my intention to use instead <a href="http://rvm.beginrescueend.com/">rvm</a>, I&#8217;ll settle for a system level Ruby at 32bit and I prefer to compile every new virtual environment at 64bit (from this <a href="http://amerine.net/2010/02/24/rvm-rails3-ruby-1-9-2-setup.html">tutorial</a>)</p>

<p>Therefore proceed as follows:</p>

<h1>Step 1: Install rvm</h1>

<p>Launch in a console this command and follow the instructions:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> curl http:<span style="color: #000000; font-weight: bold;">//</span>rvm.beginrescueend.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>rvm-install-head <span style="color: #7a0874; font-weight: bold;">&#41;</span></div></div>

<h2>Step 2: Install Ruby 1.9.2</h2>

<p>Type the following commands and verify that you have version 1.9.2 installed.</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rvm <span style="color: #c20cb9; font-weight: bold;">install</span> 1.9.2 <span style="color: #660033;">-C</span> <span style="color: #660033;">--with-readline-dir</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>,--build=x86_64-apple-darwin10<br />
rvm 1.9.2<br />
ruby <span style="color: #660033;">-v</span></div></div>

<h1>Step 3: Create a Rails3 gemset</h1>

<p>Create a Rails3 gemset and activate it as default:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rvm use <span style="color: #660033;">--create</span> 1.9.2<span style="color: #000000; font-weight: bold;">@</span>rails3 <br />
rvm 1.9.2<span style="color: #000000; font-weight: bold;">@</span>rails3 <span style="color: #660033;">--default</span></div></div>

<h1>Step 4: Install Rails3 and database drivers for <span class="caps">SQL</span>ite and MySQL</h1>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gem <span style="color: #c20cb9; font-weight: bold;">install</span> sqlite3-ruby<br />
<span style="color: #c20cb9; font-weight: bold;">env</span> <span style="color: #007800;">ARCHFLAGS</span>=<span style="color: #ff0000;">&quot;-arch x86_64&quot;</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> mysql <span style="color: #660033;">--</span> <span style="color: #660033;">--with-mysql-config</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysql_config<br />
gem <span style="color: #c20cb9; font-weight: bold;">install</span> rails</div></div>

<p>In this tutorial we&#8217;ve then installed MySQL and Ruby 1.9.2 from source. Now that all the packages have been compiled to 64bit we should not find errors while installing other application&#8217;s gems.</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fxponrails.net%2F2010%2F09%2F13%2Fhow-to-install-mysql-and-rails-on-osx-snow-leopard%2F&amp;linkname=How%20to%20install%20MySQL%20and%20Rails%20on%20Osx%20Snow%20Leopard">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://xponrails.net/2010/09/13/how-to-install-mysql-and-rails-on-osx-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to create multiple Django environments using virtualenv</title>
		<link>http://xponrails.net/2010/08/30/how-to-create-multiple-django-environments-using-virtualenv/</link>
		<comments>http://xponrails.net/2010/08/30/how-to-create-multiple-django-environments-using-virtualenv/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 06:11:33 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[virtualenv]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=134</guid>
		<description><![CDATA[ORIGINAL POST

Often we must work on various Django applications, each one dependent on different set of  libraries. 

For examples, we are working on a Django 1.1 project and and we need to start a new one with the latest version of the framework. 

The best solution is to keep the various environments separate, in [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.devinterface.com/2010/08/how-to-create-multiple-django-environments-using-virtualenv/"><span class="caps">ORIGINAL POST</span></a></p>

<p>Often we must work on various <a href="http://www.djangoproject.com/">Django</a> applications, each one dependent on different set of  libraries. </p>

<p>For examples, we are working on a Django 1.1 project and and we need to start a new one with the latest version of the framework. </p>

<p>The best solution is to keep the various environments separate, in order to ensure that each project accesses only the libraries which it depends. </p>

<p>Python offers us <a href="http://pypi.python.org/pypi/virtualenv">virtualenv</a>, a tool to create multiple isolated environments. Each environment is completely independent from the others and from the installed packages in system&#8217;s site-packages folder. </p>

<p>Let&#8217;s then see how to create a virtualenv and install the latest version of Django (today 1.2.1).</p>

<h1>1- Install python-setuptools</h1>

<p>The first thing to do is to install python-setuptools in order to have access to the command <a href="http://pypi.python.org/pypi/setuptools">easy_install</a> and to easly download packages. Alternatively, you can get the same results using the package <a href="http://pypi.python.org/pypi/pip">pip</a>.</p>

<p>Let us open a console and type the following commands:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python-setuptools<br />
Reading package lists... Done<br />
Building dependency <span style="color: #c20cb9; font-weight: bold;">tree</span> &nbsp; &nbsp; &nbsp; <br />
Reading state information... Done<br />
python-setuptools is already the newest version.<br />
<span style="color: #000000;">0</span> upgraded, <span style="color: #000000;">0</span> newly installed, <span style="color: #000000;">0</span> to remove and <span style="color: #000000;">132</span> not upgraded.<br />
stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~$</div></div>

<h1>2- Install virtualenv</h1>

<p>The second step is to install the package virtualenv using easy_install:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> easy_install virtualenv<br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #c20cb9; font-weight: bold;">sudo</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> password <span style="color: #000000; font-weight: bold;">for</span> stefano: <br />
Searching <span style="color: #000000; font-weight: bold;">for</span> virtualenv<br />
Reading http:<span style="color: #000000; font-weight: bold;">//</span>pypi.python.org<span style="color: #000000; font-weight: bold;">/</span>simple<span style="color: #000000; font-weight: bold;">/</span>virtualenv<span style="color: #000000; font-weight: bold;">/</span><br />
Reading http:<span style="color: #000000; font-weight: bold;">//</span>virtualenv.openplans.org<br />
Best match: virtualenv 1.4.9<br />
Downloading http:<span style="color: #000000; font-weight: bold;">//</span>pypi.python.org<span style="color: #000000; font-weight: bold;">/</span>packages<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>v<span style="color: #000000; font-weight: bold;">/</span>virtualenv<span style="color: #000000; font-weight: bold;">/</span>virtualenv-1.4.9.tar.gz<span style="color: #666666; font-style: italic;">#md5=c49067cab242b5ff8c7b681a5a99533a</span><br />
Processing virtualenv-1.4.9.tar.gz<br />
Running virtualenv-1.4.9<span style="color: #000000; font-weight: bold;">/</span>setup.py <span style="color: #660033;">-q</span> bdist_egg <span style="color: #660033;">--dist-dir</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>easy_install-3D0IWT<span style="color: #000000; font-weight: bold;">/</span>virtualenv-1.4.9<span style="color: #000000; font-weight: bold;">/</span>egg-dist-tmp-xe4LRm<br />
warning: no previously-included files matching <span style="color: #ff0000;">'*.*'</span> found under directory <span style="color: #ff0000;">'docs/_templates'</span><br />
Adding virtualenv 1.4.9 to easy-install.pth <span style="color: #c20cb9; font-weight: bold;">file</span><br />
Installing virtualenv script to <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<br />
<br />
Installed <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python2.6<span style="color: #000000; font-weight: bold;">/</span>dist-packages<span style="color: #000000; font-weight: bold;">/</span>virtualenv-1.4.9-py2.6.egg<br />
Processing dependencies <span style="color: #000000; font-weight: bold;">for</span> virtualenv<br />
Finished processing dependencies <span style="color: #000000; font-weight: bold;">for</span> virtualenv</div></div>

<h1>3- Create the virtual environment</h1>

<p>Once installed the package virtualenv we will need to create a space to host multiple environments. In my case, I&#8217;ve chose to create a directory in my home rather than in another writable folder in the filesystem.</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~$ <span style="color: #7a0874; font-weight: bold;">cd</span> Progetti<span style="color: #000000; font-weight: bold;">/</span>Python<span style="color: #000000; font-weight: bold;">/</span><br />
stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python$<br />
stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> virtualenvs<br />
stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python$ <span style="color: #7a0874; font-weight: bold;">cd</span> virtualenvs<span style="color: #000000; font-weight: bold;">/</span><br />
stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python<span style="color: #000000; font-weight: bold;">/</span>virtualenvs$</div></div>

<p>Now we create the real virtualenv, called &#8220;Django-1.2-env. Note the argument added to the command virtualenv, &#8211;no-site-packages: so our virtual environment will have only a minimal set of libraries in his site-packages folder. We also note that all next commands will not need access as super user via sudo.</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python<span style="color: #000000; font-weight: bold;">/</span>virtualenvs$ virtualenv <span style="color: #660033;">--no-site-packages</span> django-1.2-env<br />
New python executable <span style="color: #000000; font-weight: bold;">in</span> django-<span style="color: #000000;">1.2</span>-env<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python<br />
Installing setuptools............done.</div></div>

<h1>4- Download Django in /tmp</h1>

<p>Open a new console and download the tarball with the latest version of the framework Django. For simplicity, I&#8217;ve downloaded the package to /tmp.</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span><br />
stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:<span style="color: #000000; font-weight: bold;">/</span>tmp$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.djangoproject.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>1.2.1<span style="color: #000000; font-weight: bold;">/</span>tarball<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #660033;">--<span style="color: #000000;">2010</span>-08-28</span> 11:20:58-- &nbsp;http:<span style="color: #000000; font-weight: bold;">//</span>www.djangoproject.com<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>1.2.1<span style="color: #000000; font-weight: bold;">/</span>tarball<span style="color: #000000; font-weight: bold;">/</span><br />
Resolving www.djangoproject.com... 64.207.133.18<br />
Connecting to www.djangoproject.com<span style="color: #000000; font-weight: bold;">|</span>64.207.133.18<span style="color: #000000; font-weight: bold;">|</span>:80... connected.<br />
HTTP request sent, awaiting response... 301 Moved Permanently<br />
Location: http:<span style="color: #000000; font-weight: bold;">//</span>media.djangoproject.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>1.2<span style="color: #000000; font-weight: bold;">/</span>Django-1.2.1.tar.gz <span style="color: #7a0874; font-weight: bold;">&#91;</span>following<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #660033;">--<span style="color: #000000;">2010</span>-08-28</span> 11:20:59-- &nbsp;http:<span style="color: #000000; font-weight: bold;">//</span>media.djangoproject.com<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>1.2<span style="color: #000000; font-weight: bold;">/</span>Django-1.2.1.tar.gz<br />
Resolving media.djangoproject.com... 64.207.133.30<br />
Connecting to media.djangoproject.com<span style="color: #000000; font-weight: bold;">|</span>64.207.133.30<span style="color: #000000; font-weight: bold;">|</span>:80... connected.<br />
HTTP request sent, awaiting response... <span style="color: #000000;">200</span> OK<br />
Length: <span style="color: #000000;">6248006</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>6.0M<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>application<span style="color: #000000; font-weight: bold;">/</span>octet-stream<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
Saving to: <span style="color: #000000; font-weight: bold;">`</span>Django-1.2.1.tar.gz<span style="color: #ff0000;">'<br />
<br />
100%[======================================&gt;] 6,248,006 &nbsp; &nbsp;590K/s &nbsp; in 12s &nbsp; &nbsp; <br />
<br />
2010-08-28 11:21:11 (523 KB/s) - `Django-1.2.1.tar.gz'</span> saved <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">6248006</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">6248006</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></div></div>

<h1>5- Installing Django in virtualenv</h1>

<p>At this point, unpack Django and activate the virtualenv (via the command &#8220;source  virtualenvdir/bin/activate&#8221;). Once activated virtualenv, we&#8217;ll find his name in the shell: (django-1.2-env)stefano@stefano-laptop</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:<span style="color: #000000; font-weight: bold;">/</span>tmp$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzfv Django-1.2.1.tar.gz<br />
stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>Django-1.2.1$ <span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>stefano<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python<span style="color: #000000; font-weight: bold;">/</span>virtualenvs<span style="color: #000000; font-weight: bold;">/</span>django-1.2-env<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>activate<br />
<span style="color: #7a0874; font-weight: bold;">&#40;</span>django-1.2-env<span style="color: #7a0874; font-weight: bold;">&#41;</span>stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>Django-1.2.1$<br />
<span style="color: #7a0874; font-weight: bold;">&#40;</span>django-1.2-env<span style="color: #7a0874; font-weight: bold;">&#41;</span>stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>Django-1.2.1$ python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>

<p>We verify here that Django is installed properly in the virtual site-packages:</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python<span style="color: #000000; font-weight: bold;">/</span>virtualenvs<span style="color: #000000; font-weight: bold;">/</span>django-1.2-env$ <span style="color: #c20cb9; font-weight: bold;">ls</span> lib<span style="color: #000000; font-weight: bold;">/</span>python2.6<span style="color: #000000; font-weight: bold;">/</span>site-packages<span style="color: #000000; font-weight: bold;">/</span><br />
django&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;easy-install.pth &nbsp; setuptools-0.6c11-py2.6.egg<br />
Django-1.2.1-py2.6.egg-info &nbsp;pip-0.7.2-py2.6.egg &nbsp;setuptools.pth</div></div>

<h1>6- Create a new project</h1>

<p>At this point, we can create a new project using the command django-admin.py as required by the framework.</p>

<div class="codecolorer-container bash vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">&#40;</span>django-1.2-env<span style="color: #7a0874; font-weight: bold;">&#41;</span>stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>Django-1.2.1$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>stefano<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #7a0874; font-weight: bold;">&#40;</span>django-1.2-env<span style="color: #7a0874; font-weight: bold;">&#41;</span>stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python$ <br />
<span style="color: #7a0874; font-weight: bold;">&#40;</span>django-1.2-env<span style="color: #7a0874; font-weight: bold;">&#41;</span>stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python$ django-admin.py startproject newdjangoapp<br />
<span style="color: #7a0874; font-weight: bold;">&#40;</span>django-1.2-env<span style="color: #7a0874; font-weight: bold;">&#41;</span>stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python$ <span style="color: #7a0874; font-weight: bold;">cd</span> newdjangoapp<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #7a0874; font-weight: bold;">&#40;</span>django-1.2-env<span style="color: #7a0874; font-weight: bold;">&#41;</span>stefano<span style="color: #000000; font-weight: bold;">@</span>stefano-laptop:~<span style="color: #000000; font-weight: bold;">/</span>Progetti<span style="color: #000000; font-weight: bold;">/</span>Python<span style="color: #000000; font-weight: bold;">/</span>newdjangoapp$ <span style="color: #c20cb9; font-weight: bold;">ls</span><br />
__init__.py &nbsp;manage.py&nbsp; settings.py &nbsp;urls.py</div></div>

<p>In conclusion, we can say that virtualenv is an excellent solution to create environments fully independent and designed to accommodate each individual project. In this way, we avoid conflicts of libraries and have the opportunity to try new configurations without creating problems for other applications.</p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fxponrails.net%2F2010%2F08%2F30%2Fhow-to-create-multiple-django-environments-using-virtualenv%2F&amp;linkname=How%20to%20create%20multiple%20Django%20environments%20using%20virtualenv">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://xponrails.net/2010/08/30/how-to-create-multiple-django-environments-using-virtualenv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Patterns in Ruby: Chain of Responsibility</title>
		<link>http://xponrails.net/2010/07/30/design-patterns-in-ruby-chain-of-responsibility/</link>
		<comments>http://xponrails.net/2010/07/30/design-patterns-in-ruby-chain-of-responsibility/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 08:16:50 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=131</guid>
		<description><![CDATA[ORIGINAL POST

Today&#8217;s post discusses the first of the behavioral pattern shown by the GoF, the chain of responsibility.

This pattern expects a series of commands to be executed and a set of objects capable to handle them.
Each of these &#8220;handler&#8221; objects can send the command to the next handler in the chain if it is not [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.devinterface.com/2010/07/design-patterns-in-ruby-chain-of-responsibility/"><span class="caps">ORIGINAL POST</span></a></p>

<p>Today&#8217;s post discusses the first of the behavioral pattern shown by the GoF, the chain of responsibility.</p>

<p>This pattern expects a series of commands to be executed and a set of objects capable to handle them.<br />
Each of these &#8220;handler&#8221; objects can send the command to the next handler in the chain if it is not able to carry it out.<br />
A mechanism also exists for adding new handler objects to the end of this chain.</p>

<p>To show this pattern, we take as example a real situation very familiar to web developers.</p>

<p>Suppose that the manager must deliver a new web project.</p>

<p>To realize the entire project should be conducted several heterogeneous activities such as design the user interface, develop the application, write the user manual, deploy the application.</p>

<p>The manager doesn&#8217;t have all required skills but he can rely on a pool of developers.</p>

<p>When the activity reaches a developer, this can solve it or, if he is unable to, send it to a colleague.<br />
In this way a chain of responsibility is formed, where each actor specializes in solving only certain types of requests.</p>

<p>Let&#8217;s see how to carry out this scenario in Ruby.</p>

<p>Is therefore necessary that every element in the chain has the ability to &#8220;forward&#8221; the request to the next if he is not able to manage it.</p>

<p>So we create a module that defines this common logic and removes code duplication.</p>

<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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;">#models.rb</span><br />
<span style="color:#9966CC; font-weight:bold;">module</span> Chainable<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> next_in_chain<span style="color:#006600; font-weight:bold;">&#40;</span>link<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; @<span style="color:#9966CC; font-weight:bold;">next</span> = link<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> @<span style="color:#9966CC; font-weight:bold;">next</span> == <span style="color:#0000FF; font-weight:bold;">nil</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;This request cannot be handled!&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">return</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; @<span style="color:#9966CC; font-weight:bold;">next</span>.__send__<span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>

<p>As you can see, the next_in_chain method provides the next element in the chain.<br />
To meet demands that can not be managed, I&#8217;ve used the method_missing &#8220;pattern&#8221; : when the request can not be managed by the actor (e.g. the invoked method is not defined in the class), it will be forwarded to the next.</p>

<p>Now define the players of our example:</p>

<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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;">#models.rb</span><br />
<span style="color:#9966CC; font-weight:bold;">class</span> WebManager<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> Chainable<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>link = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; next_in_chain<span style="color:#006600; font-weight:bold;">&#40;</span>link<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; <br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> deliver_application<br />
&nbsp; &nbsp; design_interface<br />
&nbsp; &nbsp; build_application<br />
&nbsp; &nbsp; write_documentation<br />
&nbsp; &nbsp; deploy_application<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{self.class.to_s}: Application delivered&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> WebDeveloper<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> Chainable<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>link = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; next_in_chain<span style="color:#006600; font-weight:bold;">&#40;</span>link<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> build_application<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{self.class.to_s}: I'm building the application&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> deploy_application<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{self.class.to_s}: I'm deploying the application&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> WebDesigner<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> Chainable<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>link = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; next_in_chain<span style="color:#006600; font-weight:bold;">&#40;</span>link<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> design_interface<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{self.class.to_s}: I'm designing the interface&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">class</span> TechnicalWriter<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">include</span> Chainable<br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>link = <span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; next_in_chain<span style="color:#006600; font-weight:bold;">&#40;</span>link<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> write_documentation<br />
&nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{self.class.to_s}: I'm writing the documentation&quot;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>

<p>At this point we simulate our chain by running the following code:</p>

<div class="codecolorer-container ruby vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><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;">#main.rb</span><br />
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'models.rb'</span><br />
<br />
provider = WebManager.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>WebDeveloper.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>WebDesigner.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>TechnicalWriter.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
provider.<span style="color:#9900CC;">deliver_application</span><br />
provider.<span style="color:#9900CC;">make_support</span></div></div>

<p>and the output will be:</p>

<p>WebDesigner: I&#8217;m designing the interface<br />
WebDeveloper: I&#8217;m building the application<br />
TechnicalWriter: I&#8217;m writing documentation<br />
WebDeveloper: I&#8217;m deploying the application<br />
WebManager: Application delivered<br />
This request cannot be handled!</p>

<p>In conclusion, the use of this pattern is useful when we deal with heterogeneous requests and we want to make sure that these are best handled by a specific handler.<br />
It can also be used when we run commands in sequence, where each element forwards the coming command to the next handler.<br />
 <br />
An alternative to this pattern could be a decorator, able to add capacity to a specific handler. In this case a single handler will completely manage all requests.</p>

<p>In these first three articles of the series we have analyzed the first pattern shown by the GoF for each category.</p>

<p>In the coming articles I will no more follow the order set by the GoF but I&#8217;ll analyze the most useful patterns to address the most common needs.</p>

<p>Source code <a href="http://github.com/devinterface/design_patterns_in_ruby">here</a></p>

<p>Previous posts from this series:<br />
<a href="http://blog.devinterface.com/2010/06/design-patterns-in-ruby-introduction/">Design Patterns in Ruby: Introduction</a><br />
<a href="http://blog.devinterface.com/2010/06/design-patterns-in-ruby-abstract-factory/">Design Patterns in Ruby: Abstract Factory</a><br />
<a href="http://blog.devinterface.com/2010/07/design-patterns-in-ruby-adapter/">Design Patterns in Ruby: Adapter</a></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fxponrails.net%2F2010%2F07%2F30%2Fdesign-patterns-in-ruby-chain-of-responsibility%2F&amp;linkname=Design%20Patterns%20in%20Ruby%3A%20Chain%20of%20Responsibility">Share/Bookmark</a>]]></content:encoded>
			<wfw:commentRss>http://xponrails.net/2010/07/30/design-patterns-in-ruby-chain-of-responsibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Patterns in Ruby: Adapter</title>
		<link>http://xponrails.net/2010/07/07/design-patterns-in-ruby-adapter/</link>
		<comments>http://xponrails.net/2010/07/07/design-patterns-in-ruby-adapter/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 10:20:01 +0000</pubDate>
		<dc:creator>stefano</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://xponrails.net/?p=122</guid>
		<description><![CDATA[ORIGINAL POST

This second post of the series leaves for a moment the creational patterns and speaks about one of the most important structural pattern: the Adapter.

The purpose of an adapter is &#8220;to convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn&#8217;t otherwise because of incompatible interfaces.&#8221;

Suppose [...]]]></description>
			<content:encoded><![CDATA[<br />
<b>Fatal error</b>:  Out of memory (allocated 35389440) (tried to allocate 4864 bytes) in <b>/accounts/mancini/www/xponrails.net/wp-content/plugins/textile-2/class/Textile.php(3245) : runtime-created function</b> on line <b>1</b><br />

