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

<channel>
	<title>a work on process &#187; edge rails</title>
	<atom:link href="http://jystewart.net/process/tag/edge-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://jystewart.net/process</link>
	<description>notes from another web developer</description>
	<lastBuildDate>Sat, 21 Aug 2010 13:09:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Edge Rails Saves You Money (and improves performance)</title>
		<link>http://jystewart.net/process/2007/02/edge-rails-saves-you-money-and-improves-performance/</link>
		<comments>http://jystewart.net/process/2007/02/edge-rails-saves-you-money-and-improves-performance/#comments</comments>
		<pubDate>Sun, 18 Feb 2007 01:04:30 +0000</pubDate>
		<dc:creator>James Stewart</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[edge rails]]></category>
		<category><![CDATA[etag]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[http 304]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://jystewart.net/process/archives/2007/02/edge-rails-saves-you-money-and-improves-performance/</guid>
		<description><![CDATA[For anyone who serves up content that is requested repeatedly by the same user agents (be they web browsers, news readers, or any other) it can quickly get expensive (financially and in performance hits) to use up bandwidth sending the same data to the same destination over and over. HTTP provides mechanisms to deal with <a href="http://jystewart.net/process/2007/02/edge-rails-saves-you-money-and-improves-performance/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>For anyone who serves up content that is requested repeatedly by the same user agents (be they web browsers, news readers, or any other) it can quickly get expensive (financially and in performance hits) to use up bandwidth sending the same data to the same destination over and over. HTTP provides mechanisms to deal with that, but until recently they&#8217;ve been poorly supported.</p>
<p>Those costs are the reason that <a href="http://dev.rubyonrails.org/changeset/6158">this</a> is great news. DHH just committed a change to Edge Rails that automatically adds an ETag when sending a response and returns an HTTP 304 (Not Modified) when an agent comes back asking for the same content before it has changed.</p>
<p><a href="http://www.chadfowler.com/2007/2/17/edge-rails-goody-automatic-304-for-views-not-modified">Chad Fowler</a> has a good explanation on his blog, where I heard the news, and <a href="http://feedparser.org/docs/http-etag.html">this page from the Universal Feed Parser docs</a> is also a good summary.</p>
]]></content:encoded>
			<wfw:commentRss>http://jystewart.net/process/2007/02/edge-rails-saves-you-money-and-improves-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails&#8217; Improved Join Model Creation</title>
		<link>http://jystewart.net/process/2006/08/rails-improved-join-model-creation/</link>
		<comments>http://jystewart.net/process/2006/08/rails-improved-join-model-creation/#comments</comments>
		<pubDate>Sun, 20 Aug 2006 01:26:58 +0000</pubDate>
		<dc:creator>James Stewart</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[associations]]></category>
		<category><![CDATA[edge rails]]></category>
		<category><![CDATA[has_many :through]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://jystewart.net/process/archives/2006/08/rails-improved-join-model-creation/</guid>
		<description><![CDATA[Jeremy Kemper has just checked in a change to Edge Rails that fixes my biggest frustration with has_many :through. Since it&#8217;s appearance a couple of versions back, has_many :through has been a great addition to the rails associations toolkit, making the use of join models infinitely cleaner. But until recently it was rather cumbersome to <a href="http://jystewart.net/process/2006/08/rails-improved-join-model-creation/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Jeremy Kemper has just checked in a change to Edge Rails that fixes my biggest frustration with <a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000530"><em>has_many :through</em></a>. Since it&#8217;s appearance a couple of versions back, <em>has_many :through</em> has been a great addition to the rails associations toolkit, making the use of join models infinitely cleaner. But until recently it was rather cumbersome to create those relationships.</p>
<p>For example, if I wanted to add an author to a book where the relationship is defined as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">has_many <span style="color:#ff3333; font-weight:bold;">:authors</span>, <span style="color:#ff3333; font-weight:bold;">:through</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:involvements</span>, 
  <span style="color:#ff3333; font-weight:bold;">:class_name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'Contributor'</span></pre></div></div>

<p>The simplest it could be to find and create an author and set up a link was:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">book.<span style="color:#9900CC;">involvements</span>.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>
  <span style="color:#ff3333; font-weight:bold;">:author</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Contributor.<span style="color:#9900CC;">find_or_create_by_name</span><span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
book.<span style="color:#9900CC;">authors</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Now it&#8217;s as simple as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">book.<span style="color:#9900CC;">authors</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> Contributor.<span style="color:#9900CC;">find_or_create_by_name</span><span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>The one gotcha comes if your book object is a new record, and so doesn&#8217;t yet have an ID. Trying the above in that case will raise ActiveRecord::HasManyThroughCantAssociateNewRecords.</p>
<p>Since in my particular case I&#8217;m masking the association behind a proxy attribute, I considered getting around the problem by dynamically creating (and subsequently removing) <a href="http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html#M000784">after_save callbacks</a>, but for now I&#8217;ve simply changed my controller to create the associations after the record is saved. Maybe Edge Rails will have some more options to offer us before long.</p>
<p>Thanks to Josh Susser for the original report. Check out <a href="http://blog.hasmanythrough.com/articles/2006/08/19/magic-join-model-creation">his post</a> for more detail and examples.</pre>
]]></content:encoded>
			<wfw:commentRss>http://jystewart.net/process/2006/08/rails-improved-join-model-creation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
