<?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>TopSecretProject &#187; Ruby on Rails</title>
	<atom:link href="http://topsecretproject.finitestatemachine.com/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://topsecretproject.finitestatemachine.com</link>
	<description>Toby Hede on Technology</description>
	<lastBuildDate>Fri, 07 May 2010 08:37:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How-to: Organizing JavaScript in Ruby on Rails</title>
		<link>http://topsecretproject.finitestatemachine.com/2010/04/how-to-organizing-javascript-in-ruby-on-rails/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2010/04/how-to-organizing-javascript-in-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 23:18:30 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[asset_packager]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[organisation]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=150</guid>
		<description><![CDATA[I have started using what I think is a pretty robust system for handling JavaScript in my Rails projects.
The basic process is this:
1) In order to create some modularity, each controller in my system has it&#8217;s own JS file. The controller file contains the code required for the views in that controller. I still have some [...]]]></description>
			<content:encoded><![CDATA[<p>I have started using what I think is a pretty robust system for handling JavaScript in my Rails projects.</p>
<p>The basic process is this:</p>
<p>1) In order to create some modularity, each controller in my system has it&#8217;s own JS file. The controller file contains the code required for the views in that controller. I still have some higher level files for common and application-wide JS code.</p>
<p>2) Each of the controller files is scoped to a namespace:</p>
<pre>
<code>
//File: javascripts/controllers/dashboard.js
var dashboard = {
  init: function() {
    //kick-off code for the "dashboard" controller
  }
}
</code>
</pre>
<p>3) I have a view helper that appends a load command to the layout. Loading is a matter of calling the namespaced init method: <strong>$(document).ready(dashboard.init);</strong></p>
<p>The helper looks like this:</p>
<pre>
<code>
def load_controller_script(script = controller.controller_name)
  content_for :javascript do
    "&lt;script type=\"text/javascript\"&gt;$(document).ready(#{script}.init);&lt;/script&gt;".html_safe
  end
end
</code>
</pre>
<p>And is included in my layout using: <strong><%= raw(yield :javascript) -%> </strong></p>
<p>Using &#8220;raw&#8221; because I am in Rails 3 land. </p>
<p>4) At deploy time I use the awesome <strong><a href="http://github.com/sbecker/asset_packager">asset_packager</a></strong> plugin to join all of the controller files into a single file, meaning I only have a single request for JS in my production system. The namespacing ensures that there are no conflicts across the many small files. </p>
<p>That&#8217;s it!</p>
<p>I am still investigating the most robust way to setup the namespaces. The above is simple, but not necessarily the best way to go about it. </p>
<p>It would be quite a simple matter to have the files be more granular &#8211; you could actually tie them to specific actions in your system. Controller is fine for my use-case as this particular app is very JS-centric and builds actions and views using AJAX and JS in the browser (so a lot of my actions return JSON rather than HTML).</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2010/04/how-to-organizing-javascript-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Tips to Stress Less</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/11/10-tips-to-stress-less/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/11/10-tips-to-stress-less/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 00:22:11 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[mha]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[stress less]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=126</guid>
		<description><![CDATA[Busy times recently as I have two sites launched in the last week.
Lucky for me one of the sites was 10 Tips to Stress Less, full of useful advice on how to reduce stress.
The Stress Less campaign is coordinated by the Mental Health Association NSW (MHA) and has the aim of increasing community awareness of the [...]]]></description>
			<content:encoded><![CDATA[<p>Busy times recently as I have two sites launched in the last week.</p>
<p>Lucky for me one of the sites was <a href="http://stresslesstips.org.au/">10 Tips to Stress Less</a>, full of useful advice on how to reduce stress.</p>
<blockquote><p><strong>The Stress Less campaign is coordinated by the Mental Health Association NSW (MHA) and has the aim of increasing community awareness of the risks of stress and providing tips and ideas on how we can all go about reducing the impact of stress in our lives.</strong></p></blockquote>
<p>The site is running on my own social &#8220;platform&#8221; thingy.</p>
<p>Stay tuned for more on this in the very near future.</p>
<p><strong>The Techology</strong></p>
<ul>
<li>Ruby On Rails</li>
<li>Gems &amp; Plugins:
<ul>
<li>asset_packager</li>
<li>acts_as_list</li>
<li>clearance</li>
<li>declarative_authorization</li>
<li>facebooker</li>
<li>formtastic</li>
<li>hoptoad_notifier</li>
<li>paperclip</li>
<li>sanitize</li>
<li>will_paginate</li>
<li>vote_fu</li>
</ul>
</li>
<li>rSpec, Cucumber, Selenium</li>
<li>PostgreSQL</li>
<li>jQuery and a range of plugins</li>
<li>Facebook Connect, XFBML, FBJS</li>
<li>Heroku with the RPM add-on</li>
</ul>
<p>Things I learned:</p>
<ul>
<li>Facebook Connect is <strong>awesome</strong></li>
<li>Ruby on Rails continues to be <strong>awesome</strong></li>
<li><strong>Heroku is awesome times infinity</strong></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/11/10-tips-to-stress-less/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reach Out is go!</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/05/reach-out/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/05/reach-out/#comments</comments>
		<pubDate>Thu, 28 May 2009 07:25:17 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[framework of champions]]></category>
		<category><![CDATA[inspire]]></category>
		<category><![CDATA[reach-out]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=102</guid>
		<description><![CDATA[The last few weeks has been a bit of a whirlwind, but the site I have been working on since January for the Inspire Foundation is now live:
Reach Out &#8211; http://au.reachout.com/
Reach Out is a web-based service that inspires young people to help themselves through tough times, and find ways to boost their own mental health [...]]]></description>
			<content:encoded><![CDATA[<p>The last few weeks has been a bit of a whirlwind, but the site I have been working on since January for the <strong>Inspire Foundation</strong> is now live:</p>
<p><strong><a href="Reach Out - http://au.reachout.com/">Reach Out &#8211; http://au.reachout.com/</a></strong></p>
<blockquote><p><strong>Reach Out is a web-based service that inspires young people to help themselves through tough times, and find ways to boost their own mental health and wellbeing.</strong><br />
Our aim is to improve young people’s mental health and well being by building skills and providing information, support and referrals in ways we know work for young people.<br />
Reach Out is run by the Inspire Foundation (www.inspire.org.au). Inspire’s mission is to help millions of young people lead happier lives.</p></blockquote>
<p>All built using an <strong>agile methodology</strong> on <strong>Ruby on Rails</strong>, the framework of champions, of course.</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/05/reach-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>On the Rails Maturity Model</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/05/on-the-rails-maturity-model/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/05/on-the-rails-maturity-model/#comments</comments>
		<pubDate>Sun, 03 May 2009 02:46:53 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[groupthink]]></category>
		<category><![CDATA[haml]]></category>
		<category><![CDATA[railsmaturitymodel]]></category>
		<category><![CDATA[rmm]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=96</guid>
		<description><![CDATA[So the Rails Maturity Model is reality.
I hate it.
I hate the actual concept of the Rails Maturity Model.
I hate it so much it&#8217;s making me think it&#8217;s time to start moving on from Rails and Ruby. Which is probably a slight over-reaction on my part, but anyway.
At best I think RMM is a marketing exercise [...]]]></description>
			<content:encoded><![CDATA[<p>So the <a href="http://railsmaturitymodel.com/">Rails Maturity Model</a> is reality.</p>
<p>I hate it.</p>
<p><strong>I hate the actual concept of the Rails Maturity Model.</strong></p>
<p>I hate it so much it&#8217;s making me think it&#8217;s time to start moving on from Rails and Ruby. Which is probably a slight over-reaction on my part, but anyway.</p>
<p>At best I think RMM is a marketing exercise for certain Rails consultancies.</p>
<p>At worst it fosters a myopic vision of <strong>Best Practice</strong> founded in the worst kind of <strong>Group Think</strong>.</p>
<p>As Yehuda Katz posted:</p>
<blockquote><p>It makes perfect sense to create a forum for sharing and aggregating the practices that people are finding useful at the moment. What makes less sense is creating a ranked list of “popular” practices, with no obvious mechanism for mediating differences except pure popularity. And even worse is ranking firms by their aggregate level of conformance.<br />
(see <a rel="bookmark" href="http://yehudakatz.com/2009/05/02/incentivizing-innovation/">Incentivizing Innovation</a> for more).</p></blockquote>
<p>This is really the at the heart of the  problem. It&#8217;s not that we&#8217;re against a forum for sharing practice and process, but the moment we start rating and ranking organisations we are engaging in the worst kind of group think that many of us are trying desperately to avoid.</p>
<p><strong>If I wanted this sort of Best Practice, I would have stayed in the Java world &#8230;<br />
</strong></p>
<p><strong>What happens when you disagree with a number of the current  practices that are make up the RMM? </strong></p>
<p><strong>What happens in the case where you have a different </strong><strong>development </strong><strong>philosophy?</strong></p>
<p><strong>There is no capacity for dissent in the current vision of RMM.</strong></p>
<p>Full disclosure &#8211; I really saw red when I saw one of the RMM practices is &#8220;Haml for templates&#8221;. <a href="http://genshi.edgewall.org/">Genshi </a>is beautiful. ERB is adequate. <strong>Haml is clumsy, brutal, ugly, wrong and demonstrably fucked. </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/05/on-the-rails-maturity-model/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>CloudKit, pondering the future</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/03/cloudkit-pondering-the-future/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/03/cloudkit-pondering-the-future/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 10:58:36 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[Future]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active-record]]></category>
		<category><![CDATA[cloudkit]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rdbms]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=31</guid>
		<description><![CDATA[I ponder the future and trawl the web.
Recently in my travels I found the awesome CloudKit.
CloudKit provides schema-free, auto-versioned, RESTful JSON storage with optional OpenID and OAuth         support, including OAuth Discovery.
Cloudkit is similar in some respects to CouchDB &#8211; date is stored in JSON, access via REST.
I [...]]]></description>
			<content:encoded><![CDATA[<p>I ponder the future and trawl the web.</p>
<p>Recently in my travels I found the awesome <a href="http://getcloudkit.com/">CloudKit</a>.</p>
<blockquote><p>CloudKit provides schema-free, auto-versioned, RESTful JSON storage with optional OpenID and OAuth         support, including OAuth Discovery.</p></blockquote>
<p>Cloudkit is similar in some respects to CouchDB &#8211; date is stored in JSON, access via REST.</p>
<p>I looked at CouchDB in some detail for a project I have in the works and was very impressed with it&#8217;s capabilities, particularly the ability to query the datastore using JavaScript and a Map/Reduce algorithm.</p>
<p>In the end, I have decided that the benefits of persisting* with MySQL (or PostgreSQL) are too great to abandon relational technology just yet &#8211; the Rails ecosystem has such good support for these technologies in Active Record.</p>
<h5>* And yes, pun intended.</h5>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/03/cloudkit-pondering-the-future/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collecting performance metrics in Rails</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/03/collecting-performance-metrics-in-rails/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/03/collecting-performance-metrics-in-rails/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 00:18:08 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[metrics]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[scaling]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=38</guid>
		<description><![CDATA[Further to my earlier comment that:
When discussing performance no opinion should be accepted without a metric
One of the great things about Rails is there is a plugin for just about everything and collecting performance metrics is no exception. Most of this is because of Ruby and it&#8217;s incredible meta-programming flexibility (but that&#8217;s another story). Rails [...]]]></description>
			<content:encoded><![CDATA[<p>Further to my earlier comment that:</p>
<blockquote><p><strong><a href="http://topsecretproject.finitestatemachine.com/2009/03/on-performance-you-have-no-right-to-an-opinion/">When discussing performance no opinion should be accepted without a metric</a></strong></p></blockquote>
<p>One of the great things about Rails is there is a plugin for just about everything and collecting performance metrics is no exception. Most of this is because of Ruby and it&#8217;s incredible meta-programming flexibility (but that&#8217;s another story). Rails has built-in support for some basic performance monitoring on the request stack (although in recent versions this has been extracted into a plugin), but there are some excellent alternatives.</p>
<p><a href="http://newrelic.com/">RPM by NewRelic</a>:</p>
<blockquote><p>New Relic RPM is a Ruby on Rails performance monitoring application that lets you see and understand application performance metrics in real time so you can fix Rails problems fast. RPM is intuitive. It&#8217;s granular. And, it&#8217;s a 10-second Rails plug-in install.</p></blockquote>
<p><a href="http://github.com/p8/metric_fu/tree/master">metric_fu on GitHub</a>:</p>
<blockquote><p>metric_fu is a set of rake tasks that make it easy to generate metrics reports.  It uses Saikuro, Flog, Rcov, and Rails&#8217; built-in stats task to create a series of reports.  It&#8217;s designed to integrate easily with CruiseControl.rb by placing files in the Custom Build Artifacts folder.</p></blockquote>
<p>There are some great screencasts on <strong>Scaling Rails</strong> available from New Relic&#8217;s <a href="http://railslab.newrelic.com/">Rails Lab</a>. And yes, scale is orthogonal to performance, but some of the discovery techniques are the same.</p>
<p><strong>Updated</strong>:</p>
<p>A commenter has correctly pointed out that <strong>metric_fu </strong>is not a performance anaysis tool as such. I guess the subtext of what I am saying is that tools like these help track complexity &#8211; and complexity is often one of the underlying causes of performance issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/03/collecting-performance-metrics-in-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Filtering and Named Scopes</title>
		<link>http://topsecretproject.finitestatemachine.com/2009/03/filtering-and-named-scopes/</link>
		<comments>http://topsecretproject.finitestatemachine.com/2009/03/filtering-and-named-scopes/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 11:33:17 +0000</pubDate>
		<dc:creator>tobyhede</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active-record]]></category>

		<guid isPermaLink="false">http://topsecretproject.finitestatemachine.com/?p=8</guid>
		<description><![CDATA[I have been delighting in the power of Active Record&#8217;s Named Scopes and recently discovered is a  technique for cleanly adding user-driven filtering to Active Record models using Named Scopes and a little bit of Ruby magic.
Named Scopes provide a clean way of adding finders to your Active Record Models &#8211; collecting complex finder [...]]]></description>
			<content:encoded><![CDATA[<p>I have been delighting in the power of Active Record&#8217;s <strong>Named Scopes</strong> and recently discovered is a  technique for cleanly adding user-driven filtering to Active Record models using Named Scopes and a little bit of Ruby magic.</p>
<p>Named Scopes provide a clean way of adding finders to your Active Record Models &#8211; collecting complex finder logic into granular methods that can then be chained together to perform complex combinations of queries. Named scopes are eminently testable as each defined scope can be tested individually, as well as the actual combinations of scope-chains.</p>
<p>Take the following example from some recent production code:<br />
<code lang="ruby"><br />
named_scope :by_author, lambda { |*args| {:conditions =>; ["author_id = ?", args.first] }}</p>
<p>named_scope :by_state, lambda { |*args| { :conditions => ["state = ?", args.first || "published"]<br />
}}</p>
<p>named_scope :by_date, lambda { |*args| {:conditions => ["published_at BETWEEN ? AND ? OR updated_at BETWEEN ? AND ?", args.first[0], args.first[1] || Time.now, args.first[0], args.first[1] || Time.now]<br />
}}<br />
</code></p>
<p>As you can see, some quite complex logic can be wrapped into the named scopes, including parameters. </p>
<p>The scopes can be chained, which wraps everything into a single query:</p>
<p><code lang="ruby"><br />
Model.by_author(author_id).by_state("published").by_date(10.days.ago)<br />
</code></p>
<p>Once you have your named scopes set up, you can add some magic to dynamically chain them for user-based filtering.</p>
<p>What follows is from Caboose&#8217;s: <a href="http://www.caboo.se/articles/2008/8/26/the-awesomest-filter-and-sort-ever">The awesomest filter and sort ever</a></p>
<p>In the controller I set up some code to grab incoming parameters and pass them to the Model (in this case called BlogPost). </p>
<p><code lang="ruby"><br />
filter_opts = {}<br />
filter_opts[:page] = params[:page] || 1<br />
filter_opts[:author] = params[:user]<br />
filter_opts[:state] = params[:state]<br />
filter_opts[:date] = [start_date, end_date]</p>
<p>@blog_posts = BlogPost.find_by_filter(filter_opts)<br />
</code></p>
<p>I have removed some of the processing logic here, but the idea is that the user selects from a range of filtering options in the User Interface (selecting a date range, for example) and the controller grabs, cleans and validates these as appropriate and passes it through to the model.</p>
<p>The <strong>find_by_filter</strong> method is where all of the magic happens. We add the valid scopes to an array, and then chain them all together using <strong>inject</strong>.</p>
<p><code lang="ruby"><br />
def self.find_by_filter(opts = {})<br />
scopes = []</p>
<p>scopes =>; [:by_author, opts[:author] ] if opts[:author]<br />
scopes => [:by_state, opts[:state]] if opts[:state]<br />
scopes => [:by_date, opts[:date]]  if opts[:date]</p>
<p>order = opts[:order] || "published_at DESC"<br />
page = opts[:page] || 1</p>
<p>scopes.inject(BlogPost) {|model,scope|<br />
model.scopes[scope[0]].call(model, scope[1])<br />
}.paginate(:all, <img src='http://topsecretproject.finitestatemachine.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder => order, :page => page)<br />
end<br />
</code></p>
<p>The final line is the magic. Using inject with the model as the accumulator, basically emulates the chained call we saw earlier (by_author.by_state.by_date), but with the added advantage in this instance that only the scopes with the relevant options (defined in <strong>opts</strong>) are called by the find_by_filter.</p>
<p>As you can see, not only are the named scopes chained together, but I am adding paginate for good measure. Records are cleanly paginated</p>
<p>For more information on named scopes see <a href="http://guides.rubyonrails.org/active_record_querying.html#_named_scopes"><br />
Ruby on Rails Active Record Guide</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://topsecretproject.finitestatemachine.com/2009/03/filtering-and-named-scopes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
