<?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>A Tempest of Thoughts &#187; Rails</title>
	<atom:link href="http://tempe.st/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://tempe.st</link>
	<description>aka blog.to_int(:inig)</description>
	<lastBuildDate>Thu, 07 Apr 2011 08:24:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>Cookies in iFrames: how bashing my head on the table made them work in Internet Explorer</title>
		<link>http://tempe.st/2010/11/cookies-in-iframes-how-bashing-my-head-on-the-table-made-them-work-in-internet-explorer/</link>
		<comments>http://tempe.st/2010/11/cookies-in-iframes-how-bashing-my-head-on-the-table-made-them-work-in-internet-explorer/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 16:31:46 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Random Stuff]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[etags]]></category>
		<category><![CDATA[explorer]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=329</guid>
		<description><![CDATA[While working on our TTGPassport our valiant team hit a wall that most programmers hit sooner or later when working with iframes: cookies won&#8217;t work with Internet Explorer, and you will lose your session. The internet is full or remedies for this unnerving problem, most of them revolving on pseudo-magically setting the P3P header. I [...]]]></description>
			<content:encoded><![CDATA[	<p>While working on our <a href="http://ttgincontri.it">TTGPassport</a> our valiant team hit a wall that most programmers hit sooner or later when working with iframes: cookies won&#8217;t work with Internet Explorer, and you will lose your session.</p>
	<p>The internet is full or remedies for this unnerving problem, most of them revolving on pseudo-magically setting the <em>P3P</em> header. I don&#8217;t believe in pseudo-magic, so I kept googling for answers, until I found <a href="http://stackoverflow.com/questions/389456/cookie-blocked-not-saved-in-iframe-in-internet-explorer">this informing post</a>.</p>
	<p>I diligently ran through the suggestions but we had random session losses, with no reasonable explanation. We were setting our <em>P3P</em> header in a before filter (Rails application), like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ApplicationController <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::Base</span>
  before_filter <span style="color:#ff3333; font-weight:bold;">:set_p3p</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> set_p3p
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;P3P&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>=<span style="color:#996600;">'CP=&quot;NOI DSP LAW NID&quot;'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>Fearing Rails could be the culprit I changed our Apache configuration to set the header on every request, using the following directive:</p>

<div class="wp_syntax"><div class="code"><pre class="httpd" style="font-family:monospace;">Header set P3P &quot;CP=\&quot;NOI DSP LAW NID\&quot;&quot;</pre></div></div>

	<p>Unfortunately even bypassing Rails didn&#8217;t help. I was even unsure of why sometimes it worked and sometimes it didn&#8217;t (basically when explorer shows the evil red eye on the bottom of the page it means it&#8217;s blocking your cookies).</p>
	<p>I started playing around with Firebug to see what could be the problem, and finally a little lightbulb lit on top of my head: the pages that broke the session didn&#8217;t have the <em>P3P</em> header, and instead they had an <em>ETag</em> header. That means something was adding the ETag and that the browser recalled the content of the page from its cache, thus bypassing <em>P3P</em> and upsetting explorer. I disabled <em>ETags</em> in Apache:</p>

<div class="wp_syntax"><div class="code"><pre class="apache2" style="font-family:monospace;">Header unset ETag
FileETag None</pre></div></div>

	<p>Guess what? It didn&#8217;t work. Something was still setting the <em>ETag</em> header and bypassing my beloved and much needed <em>P3P</em>. The only culprit could be Ruby on Rails. I googled some more but nothing really told me how to disable <em>ETags</em> so I had to resort to some monkey patching:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActionController
  <span style="color:#9966CC; font-weight:bold;">class</span> Request
    <span style="color:#9966CC; font-weight:bold;">def</span> etag_matches?<span style="color:#006600; font-weight:bold;">&#40;</span>etag<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> Response
    <span style="color:#9966CC; font-weight:bold;">def</span> etag?
      <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>I asked our strong, silent project manager to test it because I was crossing my fingers too hard, and, finally, it worked, no <em>ETags</em> and our <em>P3P</em> header where we expected it.</p>
	<p>I hope you are reading this article because you had the same problem we had, and I hope it will help you as it helped us!</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2010/11/cookies-in-iframes-how-bashing-my-head-on-the-table-made-them-work-in-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The importance of being up-to-date</title>
		<link>http://tempe.st/2010/02/the-importance-of-being-up-to-date/</link>
		<comments>http://tempe.st/2010/02/the-importance-of-being-up-to-date/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 09:19:34 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[mikamai]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[rails 3]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=312</guid>
		<description><![CDATA[Since I started working in the web development business the release of Rails 3 has been the first time I really felt I had to understand what was going on because otherwise I would be left behind. There were simpler times where just reading the feeds of the most important blogs allowed me to be [...]]]></description>
			<content:encoded><![CDATA[	<p>Since I started working in the web development business the release of Rails 3 has been the first time I really felt I <em>had</em> to understand what was going on because otherwise I would be left behind.</p>
	<p>There were simpler times where just reading the feeds of the most important blogs allowed me to be up-to-date, but either I&#8217;m getting old or the information has become too fractioned, because this time the only reason for me (and everyone in MIKAMAI) to get started with Rails 3 was to resume a practice that unfortunately we left behind in the past year: the internal presentations.</p>
	<p>Starting last thursday, and hopefully never stopping, thursday afternoons aren&#8217;t about working for others, but are about everyone sharing his knoweledge with the others.</p>
	<p>Last thursday was obviously all about Rails 3, so a couple of us connected their macs to the big screen and demoed new features of Rails 3.</p>
	<p>It was nice, interesting questions were asked during the demos, and the overall mood was pretty good. I look forward to the next session.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2010/02/the-importance-of-being-up-to-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Legacy Path Handler, a Radiant Extension</title>
		<link>http://tempe.st/2008/09/legacy-path-handler-a-radiant-extension/</link>
		<comments>http://tempe.st/2008/09/legacy-path-handler-a-radiant-extension/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 23:42:58 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Radiant]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[extensions]]></category>

		<guid isPermaLink="false">http://tempe.st/?p=245</guid>
		<description><![CDATA[We&#8217;re preparing to deploy the new Mikamai site (not up at the time of this post), that runs on the wonderful Rails-based RadiantCMS. The VPS we&#8217;re deploying to runs on Phusion Passenger, and that means we can&#8217;t use mod_alias or mod_rewrite to 301-redirect the old URLs, already indexed by Google, to their new locations. To [...]]]></description>
			<content:encoded><![CDATA[	<p>We&#8217;re preparing to deploy the new <a href="http://mikamai.com">Mikamai</a> site (not up at the time of this post), that runs on the wonderful Rails-based <a href="http://radiantcms.org">RadiantCMS</a>.</p>
	<p>The VPS we&#8217;re deploying to runs on <a href="http://modrails.com">Phusion Passenger</a>, and that means we can&#8217;t use mod_alias or mod_rewrite to 301-redirect the old URLs, already indexed by Google, to their new locations.</p>
	<p>To solve this problem I wrote a little Radiant Extension, called <a href="http://github.com/intinig/legacy_path_handler/tree/master">LegacyPathHandler</a>, that reads a simple list of URLs from a text file and does a 301 redirection on them before handling the control to Radiant&#8217;s default SiteController.</p>
	<p>It works quite fine for us, but it has no specs/tests or documentation. Please feel free to contribute to the project if you feel you can improve it.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2008/09/legacy-path-handler-a-radiant-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Capistrano 2 goodies: A Radiant recipe library</title>
		<link>http://tempe.st/2007/10/more-capistrano-2-goodies-a-radiant-recipe-library/</link>
		<comments>http://tempe.st/2007/10/more-capistrano-2-goodies-a-radiant-recipe-library/#comments</comments>
		<pubDate>Tue, 09 Oct 2007 13:32:18 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Nimboo]]></category>
		<category><![CDATA[Radiant]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://tempe.st/2007/10/more-capistrano-2-goodies-a-radiant-recipe-library/</guid>
		<description><![CDATA[This is a followup to &#8220;A Couple of Capistrano 2 Recipes Libraries&#8221;:http://tempe.st/2007/09/a-couple-of-capistrano-2-recipes-libraries It&#8217;s official: I am a Capistranoholist, and I can&#8217;t deploy any Rails application without using Capistrano anymore. A few days ago I had to setup a Radiant site for a client and I couldn&#8217;t resist writing a small capistrano recipe library (is there [...]]]></description>
			<content:encoded><![CDATA[	<p><em>This is a followup to &#8220;A Couple of Capistrano 2 Recipes Libraries&#8221;:http://tempe.st/2007/09/a-couple-of-capistrano-2-recipes-libraries</em></p>
	<p>It&#8217;s official: I am a Capistranoholist, and I can&#8217;t deploy any Rails application without using Capistrano anymore. A few days ago I had to setup a Radiant site for a client and I couldn&#8217;t resist writing a small capistrano recipe library (is there an official name for this kind of collections?) with callbacks dedicated to radiant and tasks that help managing radiant installations.</p>
	<p>As usual you can get them from the <a href="http://github.com/intinig/radiant-recipes">recipes repository</a> .</p>
	<p>After you get the recipes load them from Capfile:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'deploy'</span> <span style="color:#9966CC; font-weight:bold;">if</span> respond_to?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:namespace</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># cap2 differentiator</span>
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'config/deploy'</span>
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'lib/recipes/medlar'</span>
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'lib/recipes/radiant'</span></pre></div></div>

	<p>Now you will have one more callback and an overridden deploy:cold task:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  after <span style="color:#996600;">&quot;deploy:migrate&quot;</span>, <span style="color:#996600;">&quot;deploy:radiant:migrate:extensions&quot;</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Overridden deploy:cold for Radiant.&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:cold</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    update
    <span style="color:#996600;">&quot;radiant:bootstrap&quot;</span>
    start
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>The overridden task bootstraps radiant during deploy:cold (but assumes you use it only the first time you deploy!), and the callback migrates radiant extensions whenever you migrate your db.</p>
	<p>If you don&#8217;t need the radiant recipes but you are using the medlar namespace I suggest you update from svn, there have been a lot of fixes to the recipes.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2007/10/more-capistrano-2-goodies-a-radiant-recipe-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A couple of capistrano 2 recipes libraries</title>
		<link>http://tempe.st/2007/09/a-couple-of-capistrano-2-recipes-libraries/</link>
		<comments>http://tempe.st/2007/09/a-couple-of-capistrano-2-recipes-libraries/#comments</comments>
		<pubDate>Thu, 20 Sep 2007 15:26:58 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Nimboo]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://tempe.st/2007/09/a-couple-of-capistrano-2-recipes-libraries/</guid>
		<description><![CDATA[I kept playing with Capistrano 2 after my last article, and I&#8217;ve refactored quite a bit my recipes, finally moving them in their own subversion repository. This allows much quicker deployment with my new rails applications. Here&#8217;s how I do it: $ rails my_new_application $ cd my_new_application $ capify . Then I edit Capfile: load [...]]]></description>
			<content:encoded><![CDATA[	<p>I kept playing with Capistrano 2 after my last article, and I&#8217;ve refactored quite a bit my recipes, finally moving them in their own subversion repository. This allows much quicker deployment with my new rails applications. Here&#8217;s how I do it:</p>
<pre>
$ rails my_new_application
$ cd my_new_application
$ capify .
</pre>
	<p>Then I edit <em>Capfile</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'deploy'</span> <span style="color:#9966CC; font-weight:bold;">if</span> respond_to?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:namespace</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># cap2 differentiator</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'lib/recipes/site5'</span> <span style="color:#008000; font-style:italic;"># This is my site5 recipe</span>
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'lib/recipes/medlar'</span> <span style="color:#008000; font-style:italic;"># The general use recipes</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">load</span> <span style="color:#996600;">'config/deploy'</span></pre></div></div>

	<p>The <em>site5</em> and <em>medlar</em> namespaces hold default configuration values, define some callbacks and the following tasks:</p>
<pre>
cap deploy:medlar:rails:freezer:edge   # Fetch Rails edge and puts it into sh...
cap deploy:medlar:rails:freezer:stable # Fetch Rails stable and puts it into ...
cap deploy:medlar:rails:link           # Links Rails to application/vendor
cap deploy:medlar:rails:update         # Updates the fetched version of rails.
	<p>cap deploy:site5:kill_dispatch_fcgi    # Kills Ruby instances on Site5<br />
cap deploy:site5:link_public_html      # Links public_html to current_path/pu...<br />
</pre></p>
	<p>Last but not least, here&#8217;s the simple, clean and elegant <em>deploy.rb</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;my_new_application&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;the_username&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:repository</span>,  <span style="color:#996600;">&quot;repo_address&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/home/#{user}/apps/#{application}&quot;</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;server.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;server.com&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;server.com&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

	<p>Quite readable, isn&#8217;t it? <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
	<p>The recipes are available via anonymous subversion: <a href="https://svn1.hosted-projects.com/medlar/recipes/">https://svn1.hosted-projects.com/medlar/recipes/</a></p>
	<p>Enjoy and let me know if you found them useful.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2007/09/a-couple-of-capistrano-2-recipes-libraries/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails and JavaScript: page.call gotchas</title>
		<link>http://tempe.st/2007/08/rails-and-javascript-pagecall-gotchas/</link>
		<comments>http://tempe.st/2007/08/rails-and-javascript-pagecall-gotchas/#comments</comments>
		<pubDate>Fri, 31 Aug 2007 13:38:17 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Prototype.js]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://tempe.st/2007/08/rails-and-javascript-pagecall-gotchas/</guid>
		<description><![CDATA[Ruby on Rails has wonderful out of the box javascript support, but sometimes implementing dynamic user interfaces is not so easy as it seems. In an application I&#8217;m working on I have a list of people with a checkbox each. In the load event of the page I add a click handler to every checkbox [...]]]></description>
			<content:encoded><![CDATA[	<p>Ruby on Rails has wonderful out of the box javascript support, but sometimes implementing dynamic user interfaces is not so easy as it seems.</p>
	<p>In an application I&#8217;m working on I have a list of people with a checkbox each. In the load event of the page I add a click handler to every checkbox using this javascript code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.ConfermaInvitati'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Event.<span style="color: #660066;">observe</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> clickHandler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// ... </span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> clickHandler<span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> e <span style="color: #339933;">=</span> Event.<span style="color: #660066;">element</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Updater</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">up</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'my/invited/toggle'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    parameters<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> id<span style="color: #339933;">:</span> e.<span style="color: #660066;">up</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">up</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">id</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    onLoading<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> e.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;/images/admin/spinner.gif&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    onSuccess<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #660066;">Request</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'my/refresh'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span></pre></div></div>

	<p>This works fine until I add a new person via an Ajax call. That person won&#8217;t have a <em>clickHandler</em> because the element wasn&#8217;t on the page when I called the click handler. So I thought it was time to test <em>page.call</em> in the  <em>render :update</em> block I had in the rails application.</p>
	<p>I tried this code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">render <span style="color:#ff3333; font-weight:bold;">:update</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>page<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#008000; font-style:italic;"># Do stuff that creates the new objects and adds it to the page</span>
  <span style="color:#008000; font-style:italic;"># The data I need is in @invited</span>
  page.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Event.observe($$('##{@invited.permalink} .ConfermaInvitati').first()), 'click', clickHandler)&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

	<p>Obviously that didn&#8217;t work, and it turned out I have to read documentation before doing fancy things <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
	<p>The rails docs told me that I had to use <em>call</em> passing the function name as the first argument and an array of parameters as the second argument, the problem is that <em>call</em> turns all the parameters into strings&#8212;this means I could not pass the <em>clickHandler</em> function to <em>Event.observe</em>. </p>
	<p>I found the solution in <em><<</em>. If you do <em>page << "foo"</em>, foo will be evaluated as raw javascripts. This meant I was able to do</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">page <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;Event.observe($$('##{@invited.permalink} .ConfermaInvitati').first()), 'click', clickHandler)</span></pre></div></div>

	<p>and finally have the functionality I was looking for. So remember, don&#8217;t <em>page.call</em> if you need to pass javascript variables to your functions.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2007/08/rails-and-javascript-pagecall-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sudoless Rails Stack on OSX</title>
		<link>http://tempe.st/2007/08/sudoless-rails-stack-on-osx/</link>
		<comments>http://tempe.st/2007/08/sudoless-rails-stack-on-osx/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 08:38:02 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://tempe.st/2007/08/sudoless-rails-stack-on-osx/</guid>
		<description><![CDATA[More and more of my developer friends are switching to OSX as time goes by, and they keep asking me for directions on the best setup for rails development: how to install ruby, how to install the missing libraries, and so on. My professional development life started on a PB Titanium running OSX 10.2, and [...]]]></description>
			<content:encoded><![CDATA[	<p>More and more of my developer friends are switching to OSX as time goes by, and they keep asking me for directions on the best setup for rails development: how to install ruby, how to install the missing libraries, and so on.</p>
	<p>My professional development life started on a PB Titanium running OSX 10.2, and continued through a PB Aluminium and a Macbook Pro. Each time I changed laptop I also reinstalled everything again, and each time I tried to come up with a better setup. </p>
	<p>Now I&#8217;ve finally found a setup I&#8217;m comfortable with, and it has the following advantages:</p>
	<ul>
		<li>Sudoless: everything runs from my user directory</li>
		<li>Non-system-tampering: doesn&#8217;t touch files in the original osx installation</li>
		<li>Crash-proof-easy-reinstall: you can just delete everything and reinstall without fear of rendering your system unstable</li>
		<li>Fink based: uses everything it can use from the fink repositories</li>
	</ul>
	<p>Now that I&#8217;ve sold you on my setup <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  it&#8217;s time to explain how to implement it. </p>
	<h3>Step one: XCode and Developer Tools</h3>
	<p>If you don&#8217;t have XCode already installed you can install it from the disks you got with your Mac or, better, download the newest version from <a href="http://connect.apple.com">Apple Developer Connection</a>. Once you got it installed you can proceed to the next step.</p>
	<h3>Step two: Fink</h3>
	<p>Go to the <a href="http://www.finkproject.org/download/index.php?phpLang=en">Fink Download Page</a>, and get the package that works best on your Mac (intel or powerpc). Follow the installation instructions and install the base fink system. After you&#8217;ve done that add these lines to your <em><sub>/.profile</em></p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;"># Dev Enviroment
&nbsp;
LDFLAGS=-L/sw/lib
export LDFLAGS
&nbsp;
CPPFLAGS='-I/Users/your_username/unix/include -I/sw/include'
export CPPFLAGS</pre></div></div>

	<p>_/Users/your_username/unix/include_ doesn&#8217;t exist yet, but we&#8217;ll create it when installing ruby.</p>
	<h3>Step three: Ruby from Sources</h3>
	<p>This is the first tricky part. Before OSX 10.4.6 the Ruby version shipped by Apple didn&#8217;t work with rails, so you were on your own. Now it works, but I prefer to have ruby in my home directory so I can mess with the sources and with the gem files and upgrade painlessly. So <a href="http://www.ruby-lang.org/en/downloads">download the latest ruby</a> sources and unpack them wherever you wish (I like <em></sub>/src</em>).</p>
	<p>Now you&#8217;re ready to go. First make sure you have readline and readline5-shlibs installed via fink so you can have a comfortable irb environment:</p>
<pre>
user$ fink install readline readline5-shlibs
</pre> 
	<p>After that it&#8217;s time for ruby:</p>
<pre>
user$ cd &lt;sub&gt;/src/ruby-1.8.6
user$ ./configure &lt;del&gt;-prefix=/Users/your_username/unix
user$ make &#38;&#38; make install
</pre>
	<p>The whole magic (and it&#8217;s not a big magic btw) is in <em></del>-prefix</em>. Installing ruby will create the /Users/your_username/unix path. Now it&#8217; time to add the <em>unix</em> dir to $PATH. Edit <em></sub>/profile</em> once again and add these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">PATH=/Users/your_username/unix/bin:/usr/local/mysql/bin:/usr/local/sbin:$PATH
export PATH</pre></div></div>

	<h3>Step four: MySQL</h3>
	<p>Quite simple with the packages from <a href="http://mysql.com">mysql.com</a>.</p>
	<h3>Step five: Last but not least, rubygems</h3>
	<p>Fetch the gem package from <a href="http://rubyforge.org/frs/?group_id=126">RubyForge</a> and install it:</p>
<pre>
user$ cd src/unpacked-rubygems-directory
user$ ruby setup.rb
</pre>
	<h3>Step six: This is the real last step <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &#8211; Rails and a little hack</h3>
	<p>Now you&#8217;re free to install rails (and friends) using</p>
<pre>
user$ gem install rails --include-dependencies
user$ gem install mysql-ruby
user$ gem install capistrano --include-dependencies
user$ gem install mongrel --include-dependencies
</pre>
	<p>The small hack I was talking about is a symlink:</p>
<pre>
user$ sudo mv /usr/bin/ruby /usr/bin/ruby-apple
user$ sudo ln -s /Users/your_username/unix/bin/ruby /usr/bin/ruby
</pre>
	<p>This way applications that insist on using <em>/usr/bin/ruby</em> (TextMate&#8217;s RubyMate for example) will work fine. </p>
	<p>Have fun with your self-made rails stack <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2007/08/sudoless-rails-stack-on-osx/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Capistrano 2 Callbacks</title>
		<link>http://tempe.st/2007/08/capistrano-2-callbacks/</link>
		<comments>http://tempe.st/2007/08/capistrano-2-callbacks/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 09:09:28 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://tempe.st/2007/08/capistrano-2-callbacks/</guid>
		<description><![CDATA[Converting the callbacks in my cap recipes to the new capistrano 2 format wasn&#8217;t as easy as I thought it would be. It turned out I had to use fully qualified task names in the after callback instead of the non-namespaced-names. Here&#8217;s a sample of working callbacks: namespace :deploy do after &#34;deploy:setup&#34;, &#34;deploy:sposivip:create_galleries&#34;, &#34;deploy:sposivip:freeze_rails&#34; after [...]]]></description>
			<content:encoded><![CDATA[	<p>Converting the callbacks in my cap recipes to the new capistrano 2 format wasn&#8217;t as easy as I thought it would be. It turned out I had to use fully qualified task names in the after callback instead of the non-namespaced-names.</p>
	<p>Here&#8217;s a sample of working callbacks:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  after <span style="color:#996600;">&quot;deploy:setup&quot;</span>, <span style="color:#996600;">&quot;deploy:sposivip:create_galleries&quot;</span>, <span style="color:#996600;">&quot;deploy:sposivip:freeze_rails&quot;</span>
  after <span style="color:#996600;">&quot;deploy:update&quot;</span>, <span style="color:#996600;">&quot;deploy:site5:link_public_html&quot;</span>, <span style="color:#996600;">&quot;deploy:sposivip:link_rails&quot;</span>, <span style="color:#996600;">&quot;deploy:sposivip:link_galleries&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>Here I have two callbacks. The first one runs after setup, creating shared paths and freezing rails in the shared directory, so I avoid having a copy on rails in each release.</p>
	<p>The second callback runs after deploy:update, so it will be called whenever I do a simple deploy or a cold deploy, it links back various directories in the shared path and it links the shared rails in vendor.</p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2007/08/capistrano-2-callbacks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Capistrano 2 on Site5</title>
		<link>http://tempe.st/2007/07/capistrano-2-on-site5/</link>
		<comments>http://tempe.st/2007/07/capistrano-2-on-site5/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 18:21:21 +0000</pubDate>
		<dc:creator>Giovanni Intini</dc:creator>
				<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Site5]]></category>

		<guid isPermaLink="false">http://tempe.st/2007/07/capistrano-2-on-site5/</guid>
		<description><![CDATA[I finally took the time to browse the capistrano 2 sources, and after reaching enlightenment I was able to write a deploy.rb file (yes I still use capify + deploy.rb instead of Capfile) that works really fine and really sweet on Site5. Without further ado, I introduce you to deploy.rb extreme Site5 version # Necessary [...]]]></description>
			<content:encoded><![CDATA[	<p>I finally took the time to browse the capistrano 2 sources, and after reaching enlightenment I was able to write a deploy.rb file (yes I still use capify + deploy.rb instead of Capfile) that works really fine and really sweet on Site5.</p>
	<p>Without further ado, I introduce you to deploy.rb <strong>extreme Site5 version</strong> <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Necessary to run on Site5</span>
set <span style="color:#ff3333; font-weight:bold;">:use_sudo</span>, <span style="color:#0000FF; font-weight:bold;">false</span>
set <span style="color:#ff3333; font-weight:bold;">:group_writable</span>, <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Less releases, less space wasted</span>
set <span style="color:#ff3333; font-weight:bold;">:keep_releases</span>, <span style="color:#006666;">2</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># The mandatory stuff</span>
set <span style="color:#ff3333; font-weight:bold;">:application</span>, <span style="color:#996600;">&quot;YOUR_APP_NAME&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:user</span>, <span style="color:#996600;">&quot;SSH_USERNAME&quot;</span>
&nbsp;
set <span style="color:#ff3333; font-weight:bold;">:repository</span>,  <span style="color:#996600;">&quot;URL_FOR_YOUR_REPOSITORY&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># SCM information</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_username</span>, <span style="color:#996600;">&quot;SCM_USERNAME&quot;</span>
set <span style="color:#ff3333; font-weight:bold;">:scm_password</span>, <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> CLI.<span style="color:#9900CC;">password_prompt</span> <span style="color:#996600;">&quot;SVN Password: &quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># This is related to site5 too.</span>
set <span style="color:#ff3333; font-weight:bold;">:deploy_to</span>, <span style="color:#996600;">&quot;/home/#{user}/apps/#{application}&quot;</span>
&nbsp;
role <span style="color:#ff3333; font-weight:bold;">:app</span>, <span style="color:#996600;">&quot;SERVERNAME&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:web</span>, <span style="color:#996600;">&quot;SERVERNAME&quot;</span>
role <span style="color:#ff3333; font-weight:bold;">:db</span>,  <span style="color:#996600;">&quot;SERVERNAME&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:primary</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
&nbsp;
&nbsp;
<span style="color:#008000; font-style:italic;"># In the deploy namespace we override some default tasks and we define</span>
<span style="color:#008000; font-style:italic;"># the site5 namespace.</span>
namespace <span style="color:#ff3333; font-weight:bold;">:deploy</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>DESC
    Deploys <span style="color:#9966CC; font-weight:bold;">and</span> starts a <span style="color:#996600;">`cold' application. This is useful if you have not <span style="color:#000099;">\</span>
    deployed your application before, or if your application is (for some <span style="color:#000099;">\</span>
    other reason) not currently running. It will deploy the code, run any <span style="color:#000099;">\</span>
    pending migrations, and then instead of invoking `</span>deploy:restart<span style="color:#996600;">', it will <span style="color:#000099;">\</span>
    invoke `deploy:start'</span> to fire up the application servers.
  <span style="color:#9900CC;">DESC</span>
  <span style="color:#008000; font-style:italic;"># NOTE: we kill public_html so be sure to have a backup or be ok with this application</span>
  <span style="color:#008000; font-style:italic;"># being the default app for the domain.</span>
  task <span style="color:#ff3333; font-weight:bold;">:cold</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    update
    site5::link_public_html
    site5::kill_dispatch_fcgi
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>DESC
    Site5 version of restart task.
  <span style="color:#9900CC;">DESC</span>
  task <span style="color:#ff3333; font-weight:bold;">:restart</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    site5::kill_dispatch_fcgi
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  namespace <span style="color:#ff3333; font-weight:bold;">:site5</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    desc <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>DESC
      Links public_html to current_release<span style="color:#006600; font-weight:bold;">/</span>public
    DESC
    task <span style="color:#ff3333; font-weight:bold;">:link_public_html</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      run <span style="color:#996600;">&quot;cd /home/#{user}; rm -rf public_html; ln -s #{current_path}/public ./public_html&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    desc <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>DESC
      Kills Ruby instances on Site5
    DESC
    task <span style="color:#ff3333; font-weight:bold;">:kill_dispatch_fcgi</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      run <span style="color:#996600;">&quot;skill -u #{user} -c ruby&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

	<p>May your deploys be merry and bright and I wish you all your applications be white <img src='http://tempe.st/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

 ]]></content:encoded>
			<wfw:commentRss>http://tempe.st/2007/07/capistrano-2-on-site5/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

