<?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>[Be el o ge] &#187; RubyOnRails</title>
	<atom:link href="http://blog.project-sierra.de/archives/category/rubyonrails/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.project-sierra.de</link>
	<description>I &#9829; The Web</description>
	<lastBuildDate>Sun, 04 Dec 2011 18:08:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Rails 3: Improving the speed of your Ajax Application</title>
		<link>http://blog.project-sierra.de/archives/2035</link>
		<comments>http://blog.project-sierra.de/archives/2035#comments</comments>
		<pubDate>Sun, 01 May 2011 22:11:55 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=2035</guid>
		<description><![CDATA[List Kung Fu uses Ajax a lot and so far it works out pretty well. Over the past two weeks I&#8217;ve looked into improving the performance of the UI and there are a couple of things that helped a lot &#8230; <a href="http://blog.project-sierra.de/archives/2035">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p><a href="http://www.listkungfu.com">List Kung Fu</a> uses Ajax a lot and so far it works out pretty well. Over the past two weeks I&#8217;ve looked into improving the performance of the UI and there are a couple of things that helped a lot and which I want to share here.</p>
<p><strong>Returning the correct HTTP status code and optimize browser caching</strong></p>
<p>There are two status codes I mean specifically:</p>
<ul>
<li>200 &#8211; &#8220;<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.1">Ok</a>&#8220;. Tells the browser that the server was able to respond successfully to the request. The response contains the data from the server in the HTTP payload.</li>
<li>304 &#8211; &#8220;<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5">Not modified</a>&#8220;. Tells the browser that the data for the sent request did not change and that data should be loaded from the cache. In this case the response does not contain any payload.</li>
</ul>
<p>Since a &#8220;Not Modified&#8221;-message contains much less data (no content, only header) that&#8217;s what you preferably want to return to the browser. Of cause you only want to that if you are sure that the browser already has the data.</p>
<p>For my application I found that the server was returning far more often 200-responses than 304-responses which caused</p>
<ul>
<li>More data than necessary had to be transmitted.</li>
<li>More data had to be processed by the UI.</li>
</ul>
<p>Both things were slowing down the application. Just a little, but enough to be noticed in the UI. Luckily there are only a few things you need to change in your Rails application to get the right behaviour.</p>
<p><strong><em>1) Use <code>stale?</code> in your GET methods</em></strong></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> show
    <span style="color:#0066ff; font-weight:bold;">@list_item</span> = <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">list_items</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span> params<span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> stale?<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:etag</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list_item</span>, <span style="color:#ff3333; font-weight:bold;">:last_modified</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list_item</span>.<span style="color:#9900CC;">updated_at</span>.<span style="color:#9900CC;">utc</span>, <span style="color:#ff3333; font-weight:bold;">:public</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
      respond_with<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@list_item</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Stale? sends back an etag and a last_modified date in the response. With the next request to the same URL the browser will send this etag and last_modified date to the server. The stale? method then analyses both parameters and returns 304 in case they are the same or 200 plus the new content if the newly calculated values are different.</p>
<p><img src="http://blog.project-sierra.de/wp-content/uploads/2011/05/diagram.png" alt="" title="diagram" width="375" height="427" class="aligncenter size-full wp-image-2049" /></p>
<p>More information on <a href="http://api.rubyonrails.org/classes/ActionController/ConditionalGet.html#method-i-stale-3F">stale?</a> you get in Rails&#8217; <a href="http://api.rubyonrails.org/classes/ActionController/ConditionalGet.html#method-i-stale-3F">API documentation</a> and on <a href="http://guides.rubyonrails.org/caching_with_rails.html#conditional-get-support">Rails Guides</a>.</p>
<p><strong><em>2) Make sure the browser asks for new data on each request</em></strong></p>
<p>After above modifications something interesting was happening. If the same Ajax action was triggered multiple times within a short period of time, the browser wouldn&#8217;t send a request at all to the server, but instead take the data from the cache. While obviously this made the UI really fast, it wasn&#8217;t exactly what I wanted. My goal was maximum performance while guaranteeing correct and up to date data on the screen.<br />
The browser&#8217;s caching behaviour is influenced by three HTTP header flags: <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">cache-controll</a>, <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">pragma</a> and <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">expires</a>.</p>
<p>To &#8220;disable&#8221; caching in the browser all together you could send the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> set_cache_buster
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Cache-Control&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;no-cache, no-store, max-age=0, must-revalidate&quot;</span>
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Pragma&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;no-cache&quot;</span>
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Expires&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Fri, 01 Jan 1990 00:00:00 GMT&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>What I wanted however is this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> set_must_revalidate
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;Cache-Control&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;must-revalidate&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This advices the browser to check for new / updated data with each request. I added this method to my application_controller.rb and I&#8217;m calling it in a before_filter of controllers for which I want to have this flag set.</p>
<p><strong><em>3) Using stale? for GET methods which return collections (e.g. index)</em></strong></p>
<p>Above stale? example is taken from a controller&#8217;s show method. This is what you find in most examples on the web. To make this work in a method which returns a collection, like typically a controller&#8217;s index method you need to find some way to figure out whether the current collection is the same as it was for the last request.<br />
List Kung Fu has a model List which has_many ListItems. Each ListItem belongs_to a List. To be able to determine in list_items_controller whether a collection of ListItems changed, I added code which updates the list.updated_at timestamp for each write operation on a list_item.</p>
<p>In ListItem.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ListItem <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:list</span>
  after_save <span style="color:#ff3333; font-weight:bold;">:update_list</span>
  after_destroy <span style="color:#ff3333; font-weight:bold;">:update_list</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># [...]</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> update_list
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">list</span>.<span style="color:#9900CC;">updated_at</span> = <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">list</span>.<span style="color:#9900CC;">save</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Thus, in the list_items_controller the index method could look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> index
    <span style="color:#0066ff; font-weight:bold;">@list_items</span> = <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">list_items</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">if</span> stale?<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#ff3333; font-weight:bold;">:last_modified</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list</span>.<span style="color:#9900CC;">updated_at</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
      respond_with<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@list_items</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Instead of using the updated_at field I could have added a version field to the List model, but that seemed unnecessary. If the model doesn&#8217;t have a model it belongs_to, you need to find another strategy for checking whether the collection has been modified. Maybe it&#8217;s possible to calculate a checksum over all objects in the collection&#8230;</p>
<p>So much for this post. I also switched from using jQuery&#8217;s <a href="http://api.jquery.com/jQuery.getJSON/">getJSON</a> to Wycats <a href="https://github.com/wycats/jquery-offline">jquery-offline</a>. More about that in my next post.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;linkname=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2035&amp;title=Rails%203%3A%20Improving%20the%20speed%20of%20your%20Ajax%20Application" id="wpa2a_2"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/2035/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Running SQL on Heroku</title>
		<link>http://blog.project-sierra.de/archives/2027</link>
		<comments>http://blog.project-sierra.de/archives/2027#comments</comments>
		<pubDate>Sat, 09 Apr 2011 21:24:30 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[Heroku]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=2027</guid>
		<description><![CDATA[If you need to run some SQL manually on Heroku, the Heroku SQL Console is exactly what you&#8217;re searching for. It&#8217;s installed in 5 seconds: heroku plugins:install git://github.com/ddollar/heroku-sql-console.git]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>If you need to run some SQL manually on <a href="http://www.heroku.com">Heroku</a>, the <a href="https://github.com/ddollar/heroku-sql-console">Heroku SQL Console</a> is exactly what you&#8217;re searching for.</p>
<p>It&#8217;s installed in 5 seconds:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku plugins:<span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>ddollar<span style="color: #000000; font-weight: bold;">/</span>heroku-sql-console.git</pre></div></div>

<p><img src="http://blog.project-sierra.de/wp-content/uploads/2011/04/terminal.png" alt="" title="terminal" width="609" height="357" class="aligncenter size-full wp-image-2028" /></p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;linkname=Running%20SQL%20on%20Heroku" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F2027&amp;title=Running%20SQL%20on%20Heroku" id="wpa2a_4"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/2027/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3, jQuery UJS and dynamically added forms in Internet Explorer</title>
		<link>http://blog.project-sierra.de/archives/1824</link>
		<comments>http://blog.project-sierra.de/archives/1824#comments</comments>
		<pubDate>Thu, 21 Oct 2010 20:18:26 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1824</guid>
		<description><![CDATA[I guess much more specific a title for a post couldn&#8217;t be. Anyways&#8230; I&#8217;m using jQuery in my Rails projects using the jQuery UJS adapter. Moreover some of the forms are added dynamically to the page. This should not really &#8230; <a href="http://blog.project-sierra.de/archives/1824">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>I guess much more specific a title for a post couldn&#8217;t be. Anyways&#8230; I&#8217;m using jQuery in my Rails projects using the <a href="http://github.com/rails/jquery-ujs">jQuery UJS adapter</a>. Moreover some of the forms are added dynamically to the page.<br />
This should not really be a problem because jQuery UJS relies on jQuery&#8217;s <a href="http://api.jquery.com/live/">live</a> method. In fact, it really isn&#8217;t a problem in all browsers&#8230; except.. Internet Explorer.</p>
<p>In Internet Explorer for some reason (and maybe just on my specific page), the live method didn&#8217;t work with the submit event of the form. The form would just post straight to the Rails application, which is not quite what I wanted. I know there were problems with .live() and a couple of Javascript events in previous versions of jQuery, but according to the doc, that should be all good now.</p>
<p>What I did in the end is this. In jQuery UJS I changed</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;">'form[data-remote]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">callRemote</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><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></pre></div></div>

<p>to</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;">'form[data-remote]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input[type=submit]&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parentsUntil</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form[data-remote]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">last</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">callRemote</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  e.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><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></pre></div></div>

<p>So instead of binding to the submit event, I&#8217;m binding a function to the click event of the submit button. That&#8217;s not as flexible as the original code, because you need to have a submit button and it wouldn&#8217;t work if the submit is triggered from Javascript directly. For my purpose however, the trick does it.</p>
<p>This two line change took me a while to figure out, so I&#8217;m really wondering if my current approach of writing Javascript applications with a Rails backend is the best approach. The approach is a mixture of retrieving JSON on the one hand vs. Rails returning Javascript code which gets executed once the Ajax call is completed on the other hand.<br />
Alternatives would be to use <a href="http://www.javascriptmvc.com/">Javascript MVC</a>, <a href="http://www.sproutcore.com/">Sproutcore</a>, <a href="http://trac.puremvc.org/PureMVC_JS">Pure MVC</a> or <a href="http://cappuccino.org/">Cappuccino</a>. All have their advantages and disadvantages and I haven&#8217;t decided yet which one I like the best&#8230; </p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;linkname=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1824&amp;title=Rails%203%2C%20jQuery%20UJS%20and%20dynamically%20added%20forms%20in%20Internet%20Explorer" id="wpa2a_6"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1824/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get Rails Flash Messages when using Ajax</title>
		<link>http://blog.project-sierra.de/archives/1808</link>
		<comments>http://blog.project-sierra.de/archives/1808#comments</comments>
		<pubDate>Fri, 08 Oct 2010 19:25:44 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1808</guid>
		<description><![CDATA[Rails provides a very convenient way of transporting short messages from the server to the user: The Flash. So you can do for example stuff like this: class LoginsController &#60; ApplicationController def destroy session&#91;:current_user_id&#93; = nil flash&#91;:notice&#93; = &#34;You have &#8230; <a href="http://blog.project-sierra.de/archives/1808">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Rails provides a very convenient way of transporting short messages from the server to the user: <a href="http://guides.rubyonrails.org/action_controller_overview.html#the-flash">The Flash</a>.</p>
<p>So you can do for example stuff 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> LoginsController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController 
  <span style="color:#9966CC; font-weight:bold;">def</span> destroy 
    session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:current_user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#0000FF; font-weight:bold;">nil</span> 
    flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;You have successfully logged out&quot;</span>  
    redirect_to root_url 
  <span style="color:#9966CC; font-weight:bold;">end</span> 
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>If you use Ajax however the user will never see this message. You could do another Ajax request in order to update the area in your layout which displays the flash messages, but that&#8217;s pretty heavy. Better would be if the Flash messages were returned directly with the Ajax request.</p>
<p>After thinking about that for a while, I thought the cleanest solution for transporting flash messages is, to add them to the response header. So I added this method to my application controller:</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>
  after_filter <span style="color:#ff3333; font-weight:bold;">:add_flash_to_header</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> add_flash_to_header
    <span style="color:#008000; font-style:italic;"># only run this in case it's an Ajax request.</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#9966CC; font-weight:bold;">unless</span> request.<span style="color:#9900CC;">xhr</span>?
&nbsp;
    <span style="color:#008000; font-style:italic;"># add different flashes to header</span>
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'X-Flash-Error'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:error</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:error</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'X-Flash-Warning'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:warning</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:warning</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'X-Flash-Notice'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:notice</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
    response.<span style="color:#9900CC;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'X-Flash-Message'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:message</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">unless</span> flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:message</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">blank</span>?
&nbsp;
    <span style="color:#008000; font-style:italic;"># make sure flash does not appear on the next page</span>
    flash.<span style="color:#9900CC;">discard</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now, when doing an Ajax call like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists/5/edit&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>you can get the JSON data by calling</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> json <span style="color: #339933;">=</span> $.<span style="color: #660066;">parseJSON</span><span style="color: #009900;">&#40;</span> test.<span style="color: #660066;">responseText</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And you get get your flash message (assuming you created one in the edit action) by calling:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> notice <span style="color: #339933;">=</span> test.<span style="color: #660066;">getResponseHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;X-Flash-Notice&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>


<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;linkname=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1808&amp;title=How%20to%20get%20Rails%20Flash%20Messages%20when%20using%20Ajax" id="wpa2a_8"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1808/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful API with JSON messages in Rails 3 and jQuery</title>
		<link>http://blog.project-sierra.de/archives/1788</link>
		<comments>http://blog.project-sierra.de/archives/1788#comments</comments>
		<pubDate>Wed, 06 Oct 2010 19:27:15 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1788</guid>
		<description><![CDATA[Rails 3 makes it really easy to return JSON data in the HTTP response. Consider this fragment: class ListsController &#60; ApplicationController &#160; respond_to :json &#160; def index @lists = List.all respond_with&#40;@lists&#41; end &#160; # ... end index might return e.g. &#8230; <a href="http://blog.project-sierra.de/archives/1788">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Rails 3 makes it really easy to return JSON data in the HTTP response. Consider this fragment:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> ListsController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
&nbsp;
  respond_to <span style="color:#ff3333; font-weight:bold;">:json</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> index
    <span style="color:#0066ff; font-weight:bold;">@lists</span> = List.<span style="color:#9900CC;">all</span>
    respond_with<span style="color:#006600; font-weight:bold;">&#40;</span>@lists<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># ...</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>index might return e.g.</p>
<p><img src="http://blog.project-sierra.de/wp-content/uploads/2010/10/json_response.png" alt="" title="json response" width="371" height="411" class="alignnone size-full wp-image-1792" /></p>
<p>If you look at <a href="http://github.com/rails/jquery-ujs/blob/master/src/rails.js">jQuery-ujs</a> when sending an Ajax request, the content type is set to &#8216;application/x-www-form-urlencoded&#8217; by default: The data is serialized as form data and send through the wire.</p>
<p>While this is absolutely fine, I was wondering how to use &#8216;application/json&#8217; as content type when sending an Ajax request with jQuery. IMHO that&#8217;s cleaner because you then send JSON in the request and get back JSON in the response. Content types like &#8216;application/json&#8217; and &#8216;text/xml&#8217; are also much better if 3rd party applications will consume your service.</p>
<p>Rails by default creates seven different routes for a single (not nested) resource:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">          GET    <span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #7a0874; font-weight: bold;">&#40;</span>.:format<span style="color: #7a0874; font-weight: bold;">&#41;</span>               <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;index&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
    lists POST   <span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #7a0874; font-weight: bold;">&#40;</span>.:format<span style="color: #7a0874; font-weight: bold;">&#41;</span>               <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;create&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
 new_list GET    <span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #000000; font-weight: bold;">/</span>new<span style="color: #7a0874; font-weight: bold;">&#40;</span>.:format<span style="color: #7a0874; font-weight: bold;">&#41;</span>           <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;new&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
          GET    <span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #000000; font-weight: bold;">/</span>:<span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.:format<span style="color: #7a0874; font-weight: bold;">&#41;</span>           <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;show&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
          PUT    <span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #000000; font-weight: bold;">/</span>:<span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.:format<span style="color: #7a0874; font-weight: bold;">&#41;</span>           <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;update&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
     list DELETE <span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #000000; font-weight: bold;">/</span>:<span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.:format<span style="color: #7a0874; font-weight: bold;">&#41;</span>           <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;destroy&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>
edit_list GET    <span style="color: #000000; font-weight: bold;">/</span>lists<span style="color: #000000; font-weight: bold;">/</span>:id<span style="color: #000000; font-weight: bold;">/</span>edit<span style="color: #7a0874; font-weight: bold;">&#40;</span>.:format<span style="color: #7a0874; font-weight: bold;">&#41;</span>      <span style="color: #7a0874; font-weight: bold;">&#123;</span>:<span style="color: #007800;">action</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;edit&quot;</span>, :<span style="color: #007800;">controller</span>=<span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #ff0000;">&quot;lists&quot;</span><span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Below the jQuery Ajax code for each of these routes:</p>
<p><strong><code>GET /lists(.:format) {:action=>"index", :controller=>"lists"}</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong><code>POST /lists(.:format) {:action=>"create", :controller=>"lists"}</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span><span style="color: #339933;">,</span>
	data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{<span style="color: #000099; font-weight: bold;">\&quot;</span>list<span style="color: #000099; font-weight: bold;">\&quot;</span>:{<span style="color: #000099; font-weight: bold;">\&quot;</span>title<span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\&quot;</span>test<span style="color: #000099; font-weight: bold;">\&quot;</span>}}&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong><code>GET /lists/new(.:format) {:action=>"new", :controller=>"lists"}</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// .new</span>
$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists/new&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong><code>GET /lists/:id(.:format) {:action=>"show", :controller=>"lists"}</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists/3&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong><code>PUT /lists/:id(.:format) {:action=>"update", :controller=>"lists"}</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists/3&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span><span style="color: #339933;">,</span>
	data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{<span style="color: #000099; font-weight: bold;">\&quot;</span>list<span style="color: #000099; font-weight: bold;">\&quot;</span>:{<span style="color: #000099; font-weight: bold;">\&quot;</span>title<span style="color: #000099; font-weight: bold;">\&quot;</span>:<span style="color: #000099; font-weight: bold;">\&quot;</span>hallo welt<span style="color: #000099; font-weight: bold;">\&quot;</span>}}&quot;</span><span style="color: #339933;">,</span>
	beforeSend<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #009900;">&#41;</span>   
	<span style="color: #009900;">&#123;</span>
		xhr.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;X-Http-Method-Override&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;PUT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong><code>DELETE /lists/:id(.:format) {:action=>"destroy", :controller=>"lists"}</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists/3&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span><span style="color: #339933;">,</span>
	beforeSend<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #009900;">&#41;</span>   
	<span style="color: #009900;">&#123;</span>
		xhr.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;X-Http-Method-Override&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;DELETE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong><code>GET /lists/:id/edit(.:format) {:action=>"edit", :controller=>"lists"}</code></strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// .edit</span>
$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://localhost:3000/lists/3/edit&quot;</span><span style="color: #339933;">,</span>
	dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
	type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span>
	processData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Note that you need to override the HTTP method for update and destroy. You could use also type: &#8220;PUT&#8221; and type: &#8220;DELETE&#8221;, but not all browsers understand these verbs. Therefore it&#8217;s probably better to use the &#8216;X-Http-Method-Override&#8217; header instead.</p>
<p>For those routes which require to send data, the data is send as JSON. The format of the JSON string needs to match what Rails would return in the response. If you used a different JSON string, you would have to parse it server side by yourself.</p>
<p>processData is set to false. If it is &#8216;true&#8217; (the default), jQuery will try to serialize it into a form post. In this case that&#8217;s not desirable, that&#8217;s why it needs to be turned off. </p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;linkname=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1788&amp;title=RESTful%20API%20with%20JSON%20messages%20in%20Rails%203%20and%20jQuery" id="wpa2a_10"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1788/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Paperclip, Amazon S3 and CNAME&#8217;s</title>
		<link>http://blog.project-sierra.de/archives/1701</link>
		<comments>http://blog.project-sierra.de/archives/1701#comments</comments>
		<pubDate>Wed, 22 Sep 2010 22:11:18 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1701</guid>
		<description><![CDATA[On Amazon S3 you can access your files through different URL&#8217;s, depending on which suites best your requirements: Your bucket as &#8220;folder&#8221;: http://s3.amazonaws.com/your-bucket/your-file.txt As subdomain: http://your-bucket.s3.amazonaws.com/your-file.txt With a CNAME on your own domain: http://images.my-domain.com/your-file.jpg How to setup a CNAME with &#8230; <a href="http://blog.project-sierra.de/archives/1701">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>On Amazon S3 you can access your files through different URL&#8217;s, depending on which suites best your requirements:</p>
<ul>
<li>Your bucket as &#8220;folder&#8221;: http://s3.amazonaws.com/your-bucket/your-file.txt</li>
<li>As subdomain: http://your-bucket.s3.amazonaws.com/your-file.txt</li>
<li>With a CNAME on your own domain: http://images.my-domain.com/your-file.jpg</li>
</ul>
<p>How to setup a CNAME with Amazon S3 is explained pretty well <a href="http://docs.amazonwebservices.com/AmazonS3/latest/index.html?VirtualHosting.html">here</a>.</p>
<p>I had however some trouble setting up the correct URL to this CNAME in <a href="http://github.com/thoughtbot/paperclip">Paperclip</a>, the popular Rails gem for handling file uploads.</p>
<p>This is the final configuration which is working for me is:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">has_attached_file <span style="color:#ff3333; font-weight:bold;">:image</span>,
      <span style="color:#ff3333; font-weight:bold;">:storage</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'s3'</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_credentials</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:access_key_id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'S3_KEY'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:secret_access_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'S3_SECRET'</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_headers</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'Expires'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>.<span style="color:#9900CC;">year</span>.<span style="color:#9900CC;">from_now</span>.<span style="color:#9900CC;">httpdate</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_host_alias</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'subdomain.my-domain.com'</span>,
      <span style="color:#ff3333; font-weight:bold;">:bucket</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'subdomain.my-domain.com'</span>,
      <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;:s3_alias_url&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/images/:class/:id_:basename.:style.:extension&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:thumb</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'70x70#'</span>,
      							<span style="color:#ff3333; font-weight:bold;">:medium</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'350x350'</span>,
      							<span style="color:#ff3333; font-weight:bold;">:original</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'1000x1000&gt;'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:default_style</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:original</span>,
      <span style="color:#ff3333; font-weight:bold;">:convert_options</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:all</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'-strip -trim'</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>I&#8217;m using <a href="http://www.heroku.com">Heroku</a> as hosting service, therefore I save the S3 key and secret in an environment variable.<br />
:s3_host_alias is the CNAME which you need to configure for your domain. The exact same string needs to be as well the name of the bucket.<br />
Finally just assign &#8220;:s3_alias_url&#8221; to :url. Without that the URL won&#8217;t be generated correctly. You would end up with something like &#8220;http://s3.amazonaws.com/your-file.txt&#8221; which is missing entirely the bucket name and would not load the file.<br />
<del datetime="2010-09-25T10:33:25+00:00">Note that for this configuration it&#8217;s not necessary to define :bucket.</del></p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;linkname=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1701&amp;title=Paperclip%2C%20Amazon%20S3%20and%20CNAME%26%238217%3Bs" id="wpa2a_12"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1701/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serialize / Deserialize nested objects in ActiveRecord</title>
		<link>http://blog.project-sierra.de/archives/1539</link>
		<comments>http://blog.project-sierra.de/archives/1539#comments</comments>
		<pubDate>Sat, 26 Jun 2010 18:17:19 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1539</guid>
		<description><![CDATA[Using ActiveRecord&#8217;s serialize method you can save Ruby objects in a single field of your model. The serialization is done through YAML. Today I tried to save a nested object structure with this method. These are the classes: class PhotoStyle &#8230; <a href="http://blog.project-sierra.de/archives/1539">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Using ActiveRecord&#8217;s <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M001799">serialize</a> method you can save Ruby objects in a single field of your model. The serialization is done through YAML.</p>
<p>Today I tried to save a nested object structure with this method. These are the classes:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> PhotoStyle
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:image</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#0066ff; font-weight:bold;">@image</span> = StyleElement.<span style="color:#9900CC;">new</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> StyleElement
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:selector</span>, <span style="color:#ff3333; font-weight:bold;">:style</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#0066ff; font-weight:bold;">@selector</span> = <span style="color:#996600;">'*'</span>
    <span style="color:#0066ff; font-weight:bold;">@style</span> = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The model which saves a PhotoStyle object:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Photo <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  serialize <span style="color:#ff3333; font-weight:bold;">:style</span>, PhotoStyle
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This first approach didn&#8217;t quite work out. Saving the model worked fine, but when I loaded it only PhotoStyle got deserialized to the original type. The nested StyleElement didn&#8217;t:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">p</span> = Photo.<span style="color:#9900CC;">last</span>
<span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">style</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;PhotoStyle:0xb70a906c @image=#&lt;YAML::Object:0xb72079a4 @ivars={&quot;selector&quot;=&gt;&quot;#theimage&quot;, &quot;style&quot;=&gt;{&quot;border&quot;=&gt;&quot;0&quot;, &quot;box-shadow&quot;=&gt;&quot;1px 3px 15px #555&quot;}}, @class=&quot;StyleElement&quot;&gt;}, @class=&quot;PhotoStyle&quot;&gt;&gt;</span></pre></div></div>

<p>Note the YAML object assigned to the @image instance variable.</p>
<p>I&#8217;m not sure if that&#8217;s a bug in Rails3 or if that is by design. You can however &#8220;fix&#8221; it by running this code snippet when your application starts up:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC00FF; font-weight:bold;">YAML</span>::<span style="color:#6666ff; font-weight:bold;">Syck::Resolver</span>.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> transfer_with_autoload<span style="color:#006600; font-weight:bold;">&#40;</span>type, val<span style="color:#006600; font-weight:bold;">&#41;</span>
    match = type.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>object:<span style="color:#006600; font-weight:bold;">&#40;</span>\w<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>?:::\w<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    match <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> match<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">constantize</span>
    transfer_without_autoload<span style="color:#006600; font-weight:bold;">&#40;</span>type, val<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  alias_method_chain <span style="color:#ff3333; font-weight:bold;">:transfer</span>, :<span style="color:#CC0066; font-weight:bold;">autoload</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Save it e.g. in yaml_autoloader.rb in the config/initializers folder of your app.</p>
<p>Now all types will autoload:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#&lt;PhotoStyle:0xb73dcb08 @image=#&lt;StyleElement:0xb73dd058 @selector=&quot;#theimage&quot;, @style={&quot;border&quot;=&gt;&quot;0&quot;, &quot;box-shadow&quot;=&gt;&quot;1px 3px 15px #555&quot;}&gt;&gt;</span></pre></div></div>

<p>I found above code snippet <a href="http://blog.sbf5.com/?p=39">here</a>. Thanks!</p>
<p>Read more about ActiveRecord&#8217;s serialize method here: <a href="http://blog.project-sierra.de/archives/1379">Simple user preferences for your Rails app</a>.</p>
<p><strong>Update:</strong><br />
Still not sure if that&#8217;s a bug, but I submitted a <a href="https://rails.lighthouseapp.com/projects/8994/tickets/5002-nested-objects-dont-deserialized-completely-rails-3-beta-4">lighthouse ticket</a>.</p>
<p><strong>Update 2:</strong><br />
Apparently this is not a bug in Rails, but a problem in my code :-) Please see Aaron&#8217;s comment in <a href="https://rails.lighthouseapp.com/projects/8994/tickets/5002-nested-objects-dont-deserialized-completely-rails-3-beta-4">above ticket</a>. </p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;linkname=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1539&amp;title=Serialize%20%2F%20Deserialize%20nested%20objects%20in%20ActiveRecord" id="wpa2a_14"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1539/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Heroku, Rails 3, RVM and Ubuntu</title>
		<link>http://blog.project-sierra.de/archives/1534</link>
		<comments>http://blog.project-sierra.de/archives/1534#comments</comments>
		<pubDate>Tue, 15 Jun 2010 20:50:24 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1534</guid>
		<description><![CDATA[Today I tried to use Heroku on Ubuntu / RVM for a Rails 3 test app. I ran into a similar problem like I had yesterday with OpenSSL. After installing the Heroku gem: gem install heroku and running the command &#8230; <a href="http://blog.project-sierra.de/archives/1534">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Today I tried to use <a href="http://heroku.com/">Heroku</a> on Ubuntu / RVM for a Rails 3 test app. I ran into a similar problem like I had yesterday with <a href="http://blog.project-sierra.de/archives/1527">OpenSSL</a>.</p>
<p>After installing the Heroku gem:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> heroku</pre></div></div>

<p>and running the command for create a new app</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">heroku create</pre></div></div>

<p>I got this error</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>siebel<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>site_ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>rubygems<span style="color: #000000; font-weight: bold;">/</span>custom_require.rb:<span style="color: #000000;">31</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>gem_original_require<span style="color: #ff0000;">': no such file to load -- readline (LoadError)
	from /home/siebel/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'</span>
	from <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>siebel<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>heroku-1.9.10<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>heroku<span style="color: #000000; font-weight: bold;">/</span>commands<span style="color: #000000; font-weight: bold;">/</span>app.rb:<span style="color: #000000;">1</span>
	from <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>siebel<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>site_ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>rubygems<span style="color: #000000; font-weight: bold;">/</span>custom_require.rb:<span style="color: #000000;">31</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>gem_original_require<span style="color: #ff0000;">'
	from /home/siebel/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'</span>
	from <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>siebel<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>heroku-1.9.10<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>heroku<span style="color: #000000; font-weight: bold;">/</span>command.rb:<span style="color: #000000;">5</span>
	from <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>siebel<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>heroku-1.9.10<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>heroku<span style="color: #000000; font-weight: bold;">/</span>command.rb:<span style="color: #000000;">5</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>each<span style="color: #ff0000;">'
	from /home/siebel/.rvm/gems/ruby-1.8.7-p249/gems/heroku-1.9.10/lib/heroku/command.rb:5
	from /home/siebel/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'</span>
	from <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>siebel<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>rubies<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>site_ruby<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>rubygems<span style="color: #000000; font-weight: bold;">/</span>custom_require.rb:<span style="color: #000000;">31</span>:<span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span>require<span style="color: #ff0000;">'
	from /home/siebel/.rvm/gems/ruby-1.8.7-p249/gems/heroku-1.9.10/bin/heroku:7
	from /home/siebel/.rvm/gems/ruby-1.8.7-p249/bin/heroku:19:in `load'</span>
	from <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>siebel<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>heroku:<span style="color: #000000;">19</span></pre></div></div>

<p>Now, the first line looks darn familiar and so does the solution:</p>
<p>First install libreadline-dev:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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> libreadline-dev</pre></div></div>

<p>Then cd into</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">~<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249<span style="color: #000000; font-weight: bold;">/</span>ext<span style="color: #000000; font-weight: bold;">/</span>readline</pre></div></div>

<p>and build the extension:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ruby extconf.rb
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>That&#8217;s it&#8230; heroku should run after that without problems.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;linkname=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1534&amp;title=Heroku%2C%20Rails%203%2C%20RVM%20and%20Ubuntu" id="wpa2a_16"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1534/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>OpenSSL, Rails 3 and Ubuntu</title>
		<link>http://blog.project-sierra.de/archives/1527</link>
		<comments>http://blog.project-sierra.de/archives/1527#comments</comments>
		<pubDate>Mon, 14 Jun 2010 21:03:41 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1527</guid>
		<description><![CDATA[I&#8217;m using RVM on my Ubuntu box. This way I can nicely install several Ruby and Rails versions next to each other. With Rails 3 however I had a little bit of trouble. When starting the server using rails server &#8230; <a href="http://blog.project-sierra.de/archives/1527">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>I&#8217;m using <a href="http://rvm.beginrescueend.com/">RVM</a> on my Ubuntu box. This way I can nicely install several Ruby and Rails versions next to each other. With Rails 3 however I had a little bit of trouble. When starting the server using</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rails server</pre></div></div>

<p> the server started fine, but as soon as I clicked &#8220;About your application’s environment&#8221;, I got this error on the console:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">LoadError: no such <span style="color: #c20cb9; font-weight: bold;">file</span> to load <span style="color: #660033;">--</span> openssl</pre></div></div>

<p>If you&#8217;re getting this too the first thing to check is whether these packages are installed:</p>
<ul>
<li>openssl</li>
<li>libssl-dev</li>
<li>libssl0.9.8</li>
</ul>
<p>If they are and it anyway doesn&#8217;t work you want to go to the source code of your Ruby installation. In my case the source is in this path:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">~<span style="color: #000000; font-weight: bold;">/</span>.rvm<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>ruby-1.8.7-p249</pre></div></div>

<p>Now you cd to ext/openssl and run the following commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ruby extconf.rb
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>After restarting WEBrick, everything was good:</p>
<p><img src="http://blog.project-sierra.de/wp-content/uploads/2010/06/rails3.jpg" alt="" title="rails3" width="515" height="223" class="aligncenter size-full wp-image-1528" /></p>
<p>For a more complete description on how to install Rails 3 on Ubuntu using RVM, checkout this blog post by Rohit Arondekar: <a href="http://rohitarondekar.com/articles/installing-rails3-beta3-on-ubuntu-using-rvm">Installing Rails 3.0 Beta 3 on Ubuntu using RVM</a></p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;linkname=OpenSSL%2C%20Rails%203%20and%20Ubuntu" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1527&amp;title=OpenSSL%2C%20Rails%203%20and%20Ubuntu" id="wpa2a_18"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1527/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mobile_Fu, Internet Explorer and respond_to</title>
		<link>http://blog.project-sierra.de/archives/1477</link>
		<comments>http://blog.project-sierra.de/archives/1477#comments</comments>
		<pubDate>Tue, 01 Jun 2010 19:48:53 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1477</guid>
		<description><![CDATA[Today I noticed that List Kung Fu displays the mobile version of the list page when I browse there with regular desktop Internet Explorer. Surfing to the same page with Firefox or Opera on the same machine worked fine and &#8230; <a href="http://blog.project-sierra.de/archives/1477">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Today I noticed that List Kung Fu displays the mobile version of the list page when I browse there with regular desktop Internet Explorer. Surfing to the same page with Firefox or Opera on the same machine worked fine and just returned the regular HTML page.</p>
<p>So what&#8217;s up?</p>
<p>Simple&#8230; Internet Explorer sends a really funny accepts header, none of the formats actually is text/html. Thus HTML is covered with an implicit */*. That&#8217;s not awesome (in good IE manner), but not really a problem. A problem it just becomes with something like this in your controller action:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">      respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">mobile</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span>
      <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Since Internet Explorer doesn&#8217;t send an explicit accept for text/html, Rails would just default to the first format, in above case format.mobile and then correctly return the mobile version of the view. The fix is easy. Just move format.html to the first position:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">      respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">html</span>
        <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">mobile</span>
      <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now */* would default to format.html.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;linkname=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1477&amp;title=Mobile_Fu%2C%20Internet%20Explorer%20and%20respond_to" id="wpa2a_20"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1477/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple user preferences for your Rails app</title>
		<link>http://blog.project-sierra.de/archives/1379</link>
		<comments>http://blog.project-sierra.de/archives/1379#comments</comments>
		<pubDate>Sun, 09 May 2010 13:55:15 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1379</guid>
		<description><![CDATA[In almost every project you need to save settings for the users of your application. One way to do that is simply adding more and more columns to your user table. If you did that for 10 or more settings &#8230; <a href="http://blog.project-sierra.de/archives/1379">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>In almost every project you need to save settings for the users of your application. One way to do that is simply adding more and more columns to your user table. If you did that for 10 or more settings you soon will realize that this doesn&#8217;t scale very well and the user model gets quickly a lot of attributes.<br />
Another possibility would be to create another model, let&#8217;s call it UserPreferences, and create a User has many UserPreferences association. This is a fine solution, but I don&#8217;t like it much either because it&#8217;s not very flexible. In case you want to add another setting you need to create a migration and so on.</p>
<p>ActiveRecord has many cool features and one them is the ability to serialize a Ruby classes and save it away in an attribute of a model. Actually the <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002284">example usage</a> the documentation suggests is exactly about user preferences. Now, in the example they&#8217;re storing simply a hash, which is fine, but I decided I go ahead and create a class for user preferences:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> UserPreference
&nbsp;
  attr_accessor <span style="color:#ff3333; font-weight:bold;">:option1</span>, <span style="color:#ff3333; font-weight:bold;">:option2</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#0066ff; font-weight:bold;">@option1</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
    <span style="color:#0066ff; font-weight:bold;">@option2</span> = <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In order to save these user preferences in my user model, I added a column <em>prefs</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  serialize <span style="color:#ff3333; font-weight:bold;">:prefs</span>, UserPreference
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> prefs
    <span style="color:#008000; font-style:italic;"># make sure we always return a UserPreference instance</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> read_attribute<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:prefs</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#0000FF; font-weight:bold;">nil</span>?
      write_attribute <span style="color:#ff3333; font-weight:bold;">:prefs</span>, UserPreference.<span style="color:#9900CC;">new</span>
      read_attribute <span style="color:#ff3333; font-weight:bold;">:prefs</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      read_attribute <span style="color:#ff3333; font-weight:bold;">:prefs</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;">def</span> prefs=<span style="color:#006600; font-weight:bold;">&#40;</span>val<span style="color:#006600; font-weight:bold;">&#41;</span>
    write_attribute <span style="color:#ff3333; font-weight:bold;">:prefs</span>, val
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>As you can see I overrode the getter and setter for the prefs attribute to be able to return always an instance of the UserPreference class. So far so good, by now you can do things like</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">user = User.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
user.<span style="color:#9900CC;">prefs</span>.<span style="color:#9900CC;">option1</span> = <span style="color:#996600;">&quot;hello world&quot;</span>
user.<span style="color:#9900CC;">save</span>!</pre></div></div>

<p>If you need another setting, you simply can add an attribute to the UserPreference class and use it right away, without the need to create a migration for it.</p>
<p>After finishing that, I thought it would be handy to have these settings available in the user session. I&#8217;m using Authlogic, so I just added a method to the create method of the user_sessions controller:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> create
    <span style="color:#0066ff; font-weight:bold;">@user_session</span> = UserSession.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_session</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@user_session</span>.<span style="color:#9900CC;">save</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>result<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#008000; font-style:italic;"># load User Preferences into session</span>
        load_user_preferences
        <span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>load_user_preferences looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> load_user_preferences
    current_user.<span style="color:#9900CC;">prefs</span>.<span style="color:#9900CC;">instance_variable_names</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>v<span style="color:#006600; font-weight:bold;">|</span>
      session<span style="color:#006600; font-weight:bold;">&#91;</span>v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_sym</span><span style="color:#006600; font-weight:bold;">&#93;</span> = current_user.<span style="color:#9900CC;">prefs</span>.<span style="color:#9900CC;">instance_variable_get</span> v
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Now you have super simple access to the current users settings through the session:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">value = session<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:option1</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

<p>In case some of the code which gets executed for a certain request changes e.g. session[:option1], I added an after_filter which looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#9966CC; font-weight:bold;">def</span> save_user_prefs_if_changed
    changed_something = <span style="color:#0000FF; font-weight:bold;">false</span>
    current_user.<span style="color:#9900CC;">prefs</span>.<span style="color:#9900CC;">instance_variable_names</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>v<span style="color:#006600; font-weight:bold;">|</span>
      key = v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">to_sym</span>
      <span style="color:#9966CC; font-weight:bold;">unless</span> current_user.<span style="color:#9900CC;">prefs</span>.<span style="color:#9900CC;">instance_variable_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>v<span style="color:#006600; font-weight:bold;">&#41;</span> == session<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>
        current_user.<span style="color:#9900CC;">prefs</span>.<span style="color:#9900CC;">instance_variable_set</span> v, session<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>
        changed_something = <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;">unless</span> current_user.<span style="color:#0000FF; font-weight:bold;">nil</span>?
&nbsp;
    current_user.<span style="color:#9900CC;">save</span>! <span style="color:#9966CC; font-weight:bold;">if</span> changed_something <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> current_user
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This ensures that changed values in the session do get saved to the users preferences and are available when the user signs in again.</p>
<p>I like this approach because of its flexibility and usage of the session. It&#8217;s not ideal when a preference contains a lot of data that you don&#8217;t need often. You then wouldn&#8217;t like to store that in the session. In that case I was thinking about introducing a naming convention to prevent the preference from being stored in the session. For <a href="http://www.listkungfu.com">ListKungFu.com</a> however I didn&#8217;t run into this situation yet.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;linkname=Simple%20user%20preferences%20for%20your%20Rails%20app" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1379&amp;title=Simple%20user%20preferences%20for%20your%20Rails%20app" id="wpa2a_22"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1379/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Nasty bug when using your Rails / jQuery powered app with Chrome</title>
		<link>http://blog.project-sierra.de/archives/1215</link>
		<comments>http://blog.project-sierra.de/archives/1215#comments</comments>
		<pubDate>Sat, 20 Feb 2010 18:43:07 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1215</guid>
		<description><![CDATA[Today I ran into a nasty bug which is only reproducible in Google Chrome. In Firefox the very same code worked perfectly fine. The code was supposed to work like this: After the user clicked the delete icon, jQuery would &#8230; <a href="http://blog.project-sierra.de/archives/1215">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Today I ran into a nasty bug which is only reproducible in Google Chrome. In Firefox the very same code worked perfectly fine.</p>
<p><a href="http://blog.project-sierra.de/wp-content/uploads/2010/02/list.jpg"><img src="http://blog.project-sierra.de/wp-content/uploads/2010/02/list.jpg" alt="" title="list" width="305" height="101" class="alignleft size-full wp-image-1216" /></a></p>
<p>The code was supposed to work like this: After the user clicked the delete icon, jQuery would send an ajax request to the server, which then would delete the list. In the call back the UI gets updated by removing the list entry element. It&#8217;s as simple as that. The HTTP method was set to DELETE to be clean. In Firefox that worked great, in Google Chrome not at all. However you didn&#8217;t get a client side error, at least not at first, but a Rails error which would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="log" style="font-family:monospace;">Error occurred while parsing request parameters.
Contents:
&nbsp;
[object Object]
/!\ FAILSAFE /!\  Sat Feb 20 18:56:39 +0100 2010
  Status: 500 Internal Server Error
  undefined method `name' for nil:NilClass
    /home/siebel/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/whiny_nil.rb:52:in `method_missing'
    /home/siebel/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/xml_mini/rexml.rb:29:in `merge_element!'
    /home/siebel/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/xml_mini/rexml.rb:18:in `parse'
    /home/siebel/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/xml_mini.rb:12:in `__send__'
    /home/siebel/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/xml_mini.rb:12:in `parse'
    /home/siebel/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/hash/conversions.rb:164:in `from_xml'
    /home/siebel/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:34:in `parse_formatted_parameters'
    /home/siebel/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:11:in `call'
    /home/siebel/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call'
    /home/siebel/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /home/siebel/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in `call'
    /home/siebel/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:34:in `run'
    /home/siebel/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rails-2.3.5/lib/rails/rack/static.rb:31:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rails-2.3.5/lib/rails/rack/log_tailer.rb:17:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in `call'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:50:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /home/siebel/.gem/ruby/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:14:in `run'
    /home/siebel/.gem/ruby/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
    /home/siebel/projects/Memento/script/server:3
    -e:1:in `load'
    -e:1</pre></div></div>

<p>Since the server returned a HTTP 500 error, the client side displayed a message to the user that an error occurred. That certainly was ok, but why the hack did Rails throuw an error?</p>
<p>I had to google a while till I found this ticket: <a href="https://rails.lighthouseapp.com/projects/8994/tickets/3803-bug-in-chromium-with-get-parameters-when-doing-a-post-request">Bug in Chromium with GET parameters when doing a POST request</a></p>
<p>So it looked like something is going wrong when you send URL parameters alongside during a POST, PUT or DELETE. Since I&#8217;m using a URL parameter to specify the locale, I first thought that&#8217;s the issue: http://localhost:3000/lists/14<strong>?locale=en</strong>. Sadly removing it didn&#8217;t help.<br />
While searching through the code I realized that for non-GET requests I was adding data to the PUT, DELETE, POST URL by this code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ajaxSend</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> request<span style="color: #339933;">,</span> settings<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        settings.<span style="color: #660066;">data</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> SomeParameter<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Once I commented out this one line things started working. I could finally delete the list using Chrome. The question now: How do I send this additional data. Fun thing: I didn&#8217;t have to &#8230; it was already added by other parts of the code. So the real issue here was that I had two parameters with the same name in my request. This was gracefully handled but Firefox but not by Google Chrome.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;linkname=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1215&amp;title=Nasty%20bug%20when%20using%20your%20Rails%20%2F%20jQuery%20powered%20app%20with%20Chrome" id="wpa2a_24"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1215/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rails: DEPRECATION WARNING: @var will no longer be implicitly assigned to local_var.</title>
		<link>http://blog.project-sierra.de/archives/1201</link>
		<comments>http://blog.project-sierra.de/archives/1201#comments</comments>
		<pubDate>Sun, 31 Jan 2010 17:53:54 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1201</guid>
		<description><![CDATA[I just ran into an interesting warning and since it took me a few minutes to figure it out I thought I share it here. I&#8217;m rendering a partial template like this: render :partial =&#62; 'list_items/list_item', :locals =&#62; &#123; :list &#8230; <a href="http://blog.project-sierra.de/archives/1201">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>I just ran into an interesting warning and since it took me a few minutes to figure it out I thought I share it here.</p>
<p>I&#8217;m rendering a partial template like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'list_items/list_item'</span>, <span style="color:#ff3333; font-weight:bold;">:locals</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:list</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list</span>, <span style="color:#ff3333; font-weight:bold;">:list_items</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list_item</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Now, when running this code I got this deprecation warning:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">DEPRECATION WARNING: <span style="color:#0066ff; font-weight:bold;">@list_item</span> will no longer be implicitly assigned to list_item. 
<span style="color:#006600; font-weight:bold;">&#40;</span>called from _run_erb_app47views47list_items47_list_item46html46erb_locals_list_list_item_list_items_object 
at <span style="color:#006600; font-weight:bold;">/</span>home<span style="color:#006600; font-weight:bold;">/</span>stefan<span style="color:#006600; font-weight:bold;">/</span>projects<span style="color:#006600; font-weight:bold;">/</span>Memento<span style="color:#006600; font-weight:bold;">/</span>app<span style="color:#006600; font-weight:bold;">/</span>views<span style="color:#006600; font-weight:bold;">/</span>list_items<span style="color:#006600; font-weight:bold;">/</span>_list_item.<span style="color:#9900CC;">html</span>.<span style="color:#9900CC;">erb</span>:<span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>The problem here was that in the partial I&#8217;m using the local variables are named <em>list</em> and <em>list_item</em>, in the render call however I&#8217;m passing in list and list_item<strong>s</strong>. Everything still works because rails implicitly assigns @list_item to the local variable list_item. This is what the warning says&#8230;</p>
<p>So the fix is simply removing the additional &#8220;s&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'list_items/list_item'</span>, <span style="color:#ff3333; font-weight:bold;">:locals</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:list</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list</span>, <span style="color:#ff3333; font-weight:bold;">:list_item</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list_item</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Not specifically hard but yet another prove that taking &#8220;a close look&#8221; at your own code is always difficult ;-) I bet a peer what have see the problem in a sec &#8230;</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;linkname=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1201&amp;title=Rails%3A%20DEPRECATION%20WARNING%3A%20%40var%20will%20no%20longer%20be%20implicitly%20assigned%20to%20local_var." id="wpa2a_26"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1201/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Rails: content_for</title>
		<link>http://blog.project-sierra.de/archives/1182</link>
		<comments>http://blog.project-sierra.de/archives/1182#comments</comments>
		<pubDate>Sun, 17 Jan 2010 16:16:45 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1182</guid>
		<description><![CDATA[Learning Rails on a real project (ListKungFu.com) is great fun and you&#8217;ll find out everyday something else which makes Rails the awesome framework it is. In the beginning of cause, that are rather small but unbelievable convenient things, in this &#8230; <a href="http://blog.project-sierra.de/archives/1182">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Learning Rails on a real project (<a href="http://www.listkungfu.com">ListKungFu.com</a>) is great fun and you&#8217;ll find out everyday something else which makes Rails the awesome framework it is. In the beginning of cause, that are rather small but unbelievable convenient things, in this case that is: The <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#M001763">content_for</a> helper command.</p>
<p>In an application as simple as List Kung Fu most views are structured like that:</p>
<p><a href="http://blog.project-sierra.de/wp-content/uploads/2010/01/layout_and_view.png"><img src="http://blog.project-sierra.de/wp-content/uploads/2010/01/layout_and_view.png" alt="" title="layout_and_view" width="392" height="315" class="alignleft size-full wp-image-1184" /></a></p>
<p>So we have the ListKungFu logo, a profile and a logout link in the header and some notes in the footer. All this you typically would find in a layout file (application.html.erb) because it&#8217;s likely you wanna display these elements on each page of your application. The more page specific data is rendered using a template, in this case show.html.erb.</p>
<p>List Kung Fu uses a fair amount of Javascript. My first approach was putting everything in a single .js file and loading it in application.html.erb. That&#8217;s ok for the beginning but becomes pretty soon pretty ugly. First, you end up with one big Javascript file which is not really nice for maintaining, second and that&#8217;s much worse: The user&#8217;s browser is loading the Javascript code for the complete application even though just a fraction of it is used per page.</p>
<p>Obviously the first thing you wanna do is splitting up the big Javascript file. My splitting strategy goes like this:</p>
<ul>
<li>Code which is used all over the application and which might be useful even in different applications I put into application.js. This file in included in the layout file.</li>
<li>Second, I created a file called listkungfu.js containing Javascript which is also used over the whole application but is more specific and therefore unlikely to be reused in another application.</li>
<li>All Javascript code which is specific to just a small part of a application, e.g. a single view, I put into a separate file. Following above example there is for instance a file called lists_show.js for the show.html.erb view.</li>
</ul>
<p>All we have to do now is including application.js and listkungfu.js in the layout file and lists_show.js in the view template.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span>=javascript_include_tag <span style="color:#996600;">'lists_show'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>Done.</p>
<p>Hm&#8230; after loading the view in the browser and looking at the generated HTML you might not be satisfied a 100%. The Javascript files included in application.html.erb nicely line up at the <a href="http://developer.yahoo.com/performance/rules.html#js_bottom">bottom of the page</a>, but lists_show.js is loaded somewhere in the middle of the HTML.</p>
<p>So, how do we move it down? You might have guessed it: content_for to the rescue!</p>
<p>Let&#8217;s replace above code with:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%</span> content_for <span style="color:#ff3333; font-weight:bold;">:addtional_scripts</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span>=javascript_include_tag <span style="color:#996600;">'lists_show'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">%&gt;</span></pre></div></div>

<p>And yield the content at the end of the layout file:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    <span style="color:#006600; font-weight:bold;">&lt;%</span>= javascript_include_tag <span style="color:#996600;">'application'</span>, <span style="color:#996600;">'listkungfu'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
    <span style="color:#006600; font-weight:bold;">&lt;%</span>= <span style="color:#9966CC; font-weight:bold;">yield</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:addtional_scripts</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
  &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>After reloading the view in the browser you&#8217;ll find the view specific Javascript file loaded after the two general files.</p>
<p><a href="http://blog.project-sierra.de/wp-content/uploads/2010/01/scripts_end_of_page.png" rel="lightbox"><img src="http://blog.project-sierra.de/wp-content/uploads/2010/01/scripts_end_of_page-300x40.png" alt="" title="scripts_end_of_page" width="300" height="40" class="alignleft size-medium wp-image-1192" /></a></p>
<p>Very cool!</p>
<p>content_for can be used for a dozen other things, too. Think about having a side bar defined in the layout displaying view specific information, etc&#8230;</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;linkname=Learning%20Rails%3A%20content_for" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1182&amp;title=Learning%20Rails%3A%20content_for" id="wpa2a_28"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1182/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Partials in Ajax Callbacks</title>
		<link>http://blog.project-sierra.de/archives/1158</link>
		<comments>http://blog.project-sierra.de/archives/1158#comments</comments>
		<pubDate>Sat, 02 Jan 2010 17:40:17 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1158</guid>
		<description><![CDATA[When you start using Rails you pretty soon start using partials for saving forms in an extra template in order to re-use them in the different views of a CRUD interface. If you go just a little bit further you&#8217;ll &#8230; <a href="http://blog.project-sierra.de/archives/1158">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>When you start using Rails you pretty soon start using partials for saving forms in an extra template in order to re-use them in the different views of a CRUD interface.</p>
<p>If you go just a little bit further you&#8217;ll find out that partials are also very useful when building Ajax applications with Rails. Often when you do an Ajax call the one thing you want to do in the callback is updating the DOM of the page.</p>
<p><img src="http://blog.project-sierra.de/wp-content/uploads/2010/01/listall.jpg" alt="" title="listall" width="290" height="289" class="alignleft size-full wp-image-1161" /></p>
<p>When the user clicks on the plus-button in above user interface, a form will popup which allows him to add another list. Once the form is filled in it will be send to the server using an Ajax call. Finally in the callback the new list will be added to the DOM.<br />
So there are two situations when you want to render a list:</p>
<ol>
<li>When the page with all available lists is rendered.</li>
<li>When the user adds a new list.</li>
</ol>
<p>This sounds like the perfect use-case for a partial, so let&#8217;s create one. For above user interface the ERB template could look like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">&lt;li id=&quot;list_<span style="color:#006600; font-weight:bold;">&lt;%</span>=list.<span style="color:#9900CC;">id</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&quot; class=&quot;list&quot;&gt;
    &lt;div&gt;
        &lt;h1&gt;<span style="color:#006600; font-weight:bold;">&lt;%</span>= list.<span style="color:#9900CC;">title</span> == <span style="color:#996600;">''</span> ? <span style="color:#996600;">'&lt;em&gt;enter a title&lt;/em&gt;'</span> : list.<span style="color:#9900CC;">title</span>  <span style="color:#006600; font-weight:bold;">%&gt;</span>&lt;/h1&gt;
        &lt;div class=&quot;summary&quot;&gt;
          <span style="color:#006600; font-weight:bold;">&lt;%</span>= pluralize list.<span style="color:#9900CC;">list_items</span>.<span style="color:#9900CC;">length</span>, <span style="color:#996600;">'item'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span>
          , <span style="color:#006600; font-weight:bold;">&lt;%</span>= pluralize list.<span style="color:#9900CC;">list_items_done</span>, <span style="color:#996600;">'item'</span> <span style="color:#006600; font-weight:bold;">%&gt;</span> done.&lt;br/&gt;
          Last updated <span style="color:#006600; font-weight:bold;">&lt;%</span>= distance_of_time_in_words list.<span style="color:#9900CC;">updated_at</span>, <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span> <span style="color:#006600; font-weight:bold;">%&gt;</span> ago
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/li&gt;</pre></td></tr></table></div>

<p>We save this code in a file named _list.html.erb.</p>
<p>In the view which generates the complete list of lists, we call the partial from within an each loop (index.html.erb):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&lt;%-</span> <span style="color:#0066ff; font-weight:bold;">@lists</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>list<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span>
  <span style="color:#006600; font-weight:bold;">&lt;%</span>= render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'lists/list'</span>, <span style="color:#ff3333; font-weight:bold;">:object</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> list <span style="color:#006600; font-weight:bold;">%&gt;</span>
<span style="color:#006600; font-weight:bold;">&lt;%-</span> <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#006600; font-weight:bold;">-%&gt;</span></pre></td></tr></table></div>

<p>If you look back to the partial code in _list.html.erb, you&#8217;ll notice a local variable being used called <em>list</em>. By adding the parameter <em>:object => list</em> to the <em>render</em> call in index.html.erb we make this variable available in the partial.</p>
<p>Let&#8217;s finally have a look at the view for the Ajax callback. It&#8217;s saved in create.js.erb and can be as easy as this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">    var new_list = &quot;<span style="color:#006600; font-weight:bold;">&lt;%</span>=escape_javascript<span style="color:#006600; font-weight:bold;">&#40;</span>render <span style="color:#ff3333; font-weight:bold;">:partial</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'lists/list'</span>, <span style="color:#ff3333; font-weight:bold;">:object</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@list</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">%&gt;</span>&quot;;
    $(&quot;#all_lists&quot;).prepend(new_list);</pre></td></tr></table></div>

<p>All we do is assigning the list-HTML to a Javascript variable. For this we need to wrap the <em>render</em> call into an <em>escape_javascript</em>. Next we prepend this list to the ul-element using jQuery. That&#8217;s it.</p>
<p>Even though this is not a complete code example I hope it&#8217;ll point into the right direction. Please post questions as comments to this post.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;linkname=Using%20Partials%20in%20Ajax%20Callbacks" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1158&amp;title=Using%20Partials%20in%20Ajax%20Callbacks" id="wpa2a_30"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1158/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Ecosystem White Paper</title>
		<link>http://blog.project-sierra.de/archives/1065</link>
		<comments>http://blog.project-sierra.de/archives/1065#comments</comments>
		<pubDate>Mon, 16 Nov 2009 09:21:35 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=1065</guid>
		<description><![CDATA[Already around the end of October Infoether, a Rails Consulting company, released a white paper about the Ruby and Rails ecosystem. The target audience are non technical executives or business men who want to know more about Ruby and Rails &#8230; <a href="http://blog.project-sierra.de/archives/1065">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Already around the end of October <a href="http://infoether.com">Infoether</a>, a Rails Consulting company, released a <a href="http://infoether.com/ruby-and-rails-whitepaper">white paper about the Ruby and Rails ecosystem</a>.<br />
The target audience are non technical executives or business men who want to know more about Ruby and Rails in order to be able to make informed decisions in near future. Although programmers are not exactly the target audience the paper can serve as a great summary about ecosystem which has emerged  around Ruby and Rails. From the table of contents:</p>
<ul>
<li>Ruby Runtimes</li>
<li>Ruby Frameworks</li>
<li>Community: Conferences, Training, Publishing</li>
<li>Consulting</li>
<li>Implementation tools: databases, Application Management, Deployment, Hosting (Code &#038; Applications)</li>
<li>Developer &#038; Analysis Tools</li>
</ul>
<p>Here and there I got the feeling the information is not 100% complete, specially when it comes to hosting companies outside the US (e.g. UK based <a href="http://www.brightbox.co.uk/">Brightbox</a> is missing). Anyway it&#8217;s a nice, high level, summary about what going on in Ruby and Rails.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;linkname=Rails%20Ecosystem%20White%20Paper" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F1065&amp;title=Rails%20Ecosystem%20White%20Paper" id="wpa2a_32"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/1065/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails on Ubuntu 9.04</title>
		<link>http://blog.project-sierra.de/archives/982</link>
		<comments>http://blog.project-sierra.de/archives/982#comments</comments>
		<pubDate>Sun, 06 Sep 2009 16:42:13 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=982</guid>
		<description><![CDATA[Here some good advises how to install Rails on Ubuntu 9.04: Installing Ruby on Rails on Debian/Ubuntu After I finished the installation I created a new app and tried to start up the development server. That failed with below message: &#8230; <a href="http://blog.project-sierra.de/archives/982">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>Here some good advises how to install Rails on Ubuntu 9.04: <a href="http://wiki.rubyonrails.org/getting-started/installation/linux">Installing Ruby on Rails on Debian/Ubuntu</a></p>
<p>After I finished the installation I created a new app and tried to start up the development server. That failed with below message:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rails-2.0.2<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>initializer.rb:<span style="color: #000000;">159</span>:<span style="color: #000000; font-weight: bold;">in</span>
<span style="color: #000000; font-weight: bold;">`</span>require_frameworks<span style="color: #ff0000;">': no such file to load -- openssl (RuntimeError)</span></pre></div></div>

<p>To fix this you need to install OpenSSL:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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> openssl
&nbsp;
<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> libopenssl-ruby</pre></div></div>

<p>After that WEBrick started up without issues and served the standard welcome page.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;linkname=Rails%20on%20Ubuntu%209.04" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F982&amp;title=Rails%20on%20Ubuntu%209.04" id="wpa2a_34"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/982/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frontend with GWT. What about the server side?</title>
		<link>http://blog.project-sierra.de/archives/972</link>
		<comments>http://blog.project-sierra.de/archives/972#comments</comments>
		<pubDate>Sun, 06 Sep 2009 13:25:41 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=972</guid>
		<description><![CDATA[The past few weeks I&#8217;ve been playing around with the Google Web Toolkit and I&#8217;m pretty persuaded that it&#8217;s the best choice for implementing Rich Internet Applications. Google itself used it for the Google Waves front-end and for a complete &#8230; <a href="http://blog.project-sierra.de/archives/972">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p>The past few weeks I&#8217;ve been playing around with the <a href="http://code.google.com/intl/de-DE/webtoolkit/">Google Web Toolkit</a> and I&#8217;m pretty persuaded that it&#8217;s the best choice for implementing Rich Internet Applications. Google itself used it for the Google Waves front-end and for a complete re-write of the Google Adsense admin application. There are other companies out there using GWT in an enterprise environment ,e.g. <a href="http://http://www.lombardisoftware.com/">Lombardi Blueprint</a>. </p>
<p><strong>How to communicate with the server?</strong></p>
<p>GWT supports two ways to communicate with the server. The first is <a href="http://http://code.google.com/intl/de-DE/webtoolkit/doc/1.6/DevGuideServerCommunication.html#DevGuideRemoteProcedureCalls">GWT-RPC</a> which requires a Java server side because you need to implement a Servlet. Now this sounds more painful than it is. In fact it&#8217;s pretty straight forward. The really nice thing about it is, that you don&#8217;t have to think about serialization / deserialization of your objects. The Google Web Toolkit will take care of that.<br />
The second approach is rather classical and that is to send and receive JSON or XML. Clearly this enables you to use whatever server side framework and that is great. The downside of this flexibility is that you have to take care of serialization by yourself. Luckily Ryan Dewsbury provided a code generator in his <a href="http://my.safaribooksonline.com/9780321501967?portal=informit">GWT Applications Book</a> which automatically generates the serialization code for you. Check out the code on his <a href="http://www.gwtapps.com/?p=46">webpage</a>.</p>
<p><strong>Ok cool, so that means I should take which framework?</strong></p>
<p>There are so many web frameworks out there that it&#8217;s not hard to loose completely overview. For my personal preference I can narrow down the number of frameworks to consider to these two: <a href="http://rubyonrails.org/">Ruby on Rails</a> and <a href="http://grails.org/">Grails</a>, the Java web application framework based on the <a href="http://groovy.codehaus.org/">Groovy</a> programming language.</p>
<p>Ruby on Rails is currently by far the most popular web application framework. What I really love about the framework is that you get all in one. A descend MVC architecture, Templates, easy REST, testability, database migrations, a very healthy and active community (which is really really important), Ruby, hundreds of plugins, you name it. The framework has gone through two major iterations and can be considered business ready. Companies like <a href="http://www.thoughtworks.com/">Thoughtworks</a> generate a big part of their annual revenue with Ruby and Rails projects. There are great hosting companies (<a href="http://www.engineyard.com/">Engine Yard</a>, <a href="http://www.brightbox.co.uk/">BrightBox</a>, <a href="http://heroku.com/">Heroku</a> to mention just a few), the deployment <a href="http://www.loudthinking.com/posts/30-myth-1-rails-is-hard-to-deploy">became much easier</a> than in the early days and when it comes to performance you have a whole bunch of great choices to improve it (check out this series of <a href="http://railslab.newrelic.com/scaling-rails">screencasts</a>).</p>
<p>Grails uses Groovy as language. Both Grails and Groovy look very similar to Rails and Ruby. Grails is still pretty young but I believe in the coming years we will see a lot more Grails applications. One reason for this is the very tight integration with Java. So are for example most valid Java programs also valid Groovy programs. This makes it really easy for Java developers to try it out. Also Grails builds up on proven Java technologies like <a href="https://www.hibernate.org/">Hibernate</a>, <a href="http://www.opensymphony.com/sitemesh/">SiteMesh</a> and <a href="http://www.springsource.org/">Spring</a>. So though Grails might still have some quirks, the technologies underneath are out there for quite a while and used in thousands of applications. This also makes it easier to re-use existing code and infrastructure and sort of gradually move towards a more agile environment. It&#8217;s really made simple to use technologies like JMQ, JMX or libraries like <a href="http://lucene.apache.org/java/docs/">Lucene</a>.<br />
Despite Grails is build upon things you know from JEE you don&#8217;t have to go through configuration hell. Grails puts Convention over Configuration and sets useful defaults just like Rails does.</p>
<p><strong>Conclusion</strong></p>
<p>Ruby on Rails is the original, it&#8217;s proven and you finally don&#8217;t have to worry any more about the <a href="http://twittch.com/24/">Java technology stack</a>. The only downside in terms of using GWT on the front-end is that you can&#8217;t use GWT-RPC.</p>
<p>Grails is great if you need to integrate with Java. Because of the big Java community we will see more talk about Grails in future. It&#8217;s also a good choice in combination with GWT. There&#8217;s a plugin for GWT and also AppEngine.</p>
<p>All in all I believe you don&#8217;t do anything from with either framework. It&#8217;s about personal preference. I&#8217;d like to see some performance comparison between GWT-RPC and the JSON/XML approach with generated serializer though. Your choice might be influenced by existing systems or libraries you have to use. This is true in both directions. With JRuby becoming a more and more mature Ruby implementation, Java integration is not anymore just a dream, although it&#8217;s not as tight as in Groovy / Grails.</p>
<p><ins datetime="2009-09-06T15:34:50+00:00">Update:</ins><br />
<a href="http://www.ibm.com/developerworks/java/library/j-grails12168/index.html">Mastering Grails &#8211; Grails in the Enterprise</a><br />
<a href="http://www.brianlegros.com/blog/2008/01/20/proof-of-concept-learning-groovy-grails-jruby-and-rails/">Proof of Concept : Learning Groovy, Grails, JRuby, and Rails</a></p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;linkname=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F972&amp;title=Frontend%20with%20GWT.%20What%20about%20the%20server%20side%3F" id="wpa2a_36"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/972/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make Gedit more Textmate-ish</title>
		<link>http://blog.project-sierra.de/archives/968</link>
		<comments>http://blog.project-sierra.de/archives/968#comments</comments>
		<pubDate>Thu, 03 Sep 2009 19:42:45 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=968</guid>
		<description><![CDATA[Textmate seems to be the first choice as editor / IDE for Rails application development. Unfortunately Textmate is just available on Mac OS X. Luckily there&#8217;s hope, at least if you&#8217;re using Linux. With just a few commands you can &#8230; <a href="http://blog.project-sierra.de/archives/968">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p><a href="http://macromates.com/">Textmate</a> seems to be the first choice as editor / IDE for Rails application development. Unfortunately Textmate is just available on Mac OS X.</p>
<p>Luckily there&#8217;s hope, at least if you&#8217;re using Linux. With just a few commands you can pimp up your <a href="http://projects.gnome.org/gedit/">Gedit</a>, so that it has much of the functionality of Textmate (and that completely for free).</p>
<p>First you want to install some of the standard plugins, which don&#8217;t get installed by default:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><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> gedit-plugins</pre></div></div>

<p>Now, download <a href="http://github.com/lexrupy/gmate/tree/master">Gmate</a>, unpack it and execute:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sh</span> .<span style="color: #000000; font-weight: bold;">/</span>install.sh</pre></div></div>

<p>That&#8217;s it. Checkout <a href="http://blog.siverti.com.br/gmate/">Gmate&#8217;s webpage</a> for more details.</p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;linkname=Make%20Gedit%20more%20Textmate-ish" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F968&amp;title=Make%20Gedit%20more%20Textmate-ish" id="wpa2a_38"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/968/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google I/O und LA Ruby: Material für verregnete Wochenenden</title>
		<link>http://blog.project-sierra.de/archives/809</link>
		<comments>http://blog.project-sierra.de/archives/809#comments</comments>
		<pubDate>Sun, 28 Jun 2009 15:56:53 +0000</pubDate>
		<dc:creator>Stefan Siebel</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyOnRails]]></category>

		<guid isPermaLink="false">http://blog.project-sierra.de/?p=809</guid>
		<description><![CDATA[Google Web Toolkit @ Google I/O 14 Videos from LA Ruby 2009: Some Great Weekend Watching]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<!--INFOLINKS_ON-->
<p><p><a href="http://http://www.rubyinside.com/la-ruby-2009-videos-1830.html">Google Web Toolkit @ Google I/O</a><br />
<a href="http://www.rubyinside.com/la-ruby-2009-videos-1830.html">14 Videos from LA Ruby 2009: Some Great Weekend Watching</a></p>

<!--INFOLINKS_OFF-->
<!-- google_ad_section_end -->
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="Facebook" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_linkedin" href="http://www.addtoany.com/add_to/linkedin?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="LinkedIn" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/linkedin.png" width="16" height="16" alt="LinkedIn"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_slashdot" href="http://www.addtoany.com/add_to/slashdot?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="Slashdot" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/slashdot.png" width="16" height="16" alt="Slashdot"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;linkname=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.project-sierra.de%2Farchives%2F809&amp;title=Google%20I%2FO%20und%20LA%20Ruby%3A%20Material%20f%C3%BCr%20verregnete%20Wochenenden" id="wpa2a_40"><img src="http://blog.project-sierra.de/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.project-sierra.de/archives/809/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

