<?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>Dr Nic &#187; Ruby on Rails</title>
	<atom:link href="http://drnicwilliams.com/category/ruby/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Sat, 12 Nov 2011 01:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Using CoffeeScript in Rails and even on Heroku</title>
		<link>http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/</link>
		<comments>http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 12:46:52 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=713</guid>
		<description><![CDATA[I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for pure JavaScript. What is CoffeeScript? Imagine all the syntactical delights of Ruby and Haml for your JavaScript. You write in a nice language, but get normal JavaScript at runtime. All whilst having full access to 3rd-party JavaScript libraries (jQuery, PrototypeJS), debugging support (it becomes pure, [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/06/01/validate-and-save-your-ruby-in-textmate-with-secret-rubinus-superpowers/' rel='bookmark' title='Permanent Link: Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers'>Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers</a> <small>In some TextMate bundles, if you save a file it...</small></li><li><a href='http://drnicwilliams.com/2010/05/28/showcase-of-coffeescript-2-5-mins-for-your-next-dev-group-meeting/' rel='bookmark' title='Permanent Link: Showcase of CoffeeScript &#8211; 2.5 mins for your next Dev Group meeting'>Showcase of CoffeeScript &#8211; 2.5 mins for your next Dev Group meeting</a> <small> If you are giving an &#8220;Introduction to CoffeeScript&#8221; talk...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pretty excited about <a href="http://jashkenas.github.com/coffee-script/">CoffeeScript</a> as a clean-syntax replacement for pure JavaScript. </p>
<h3 id="what_is_coffeescript">What is CoffeeScript?</h3>
<p><img src="http://img.skitch.com/20100315-mq3h882gd6742tixy78mnbc5jt.png" width="550px"></p>
<p>Imagine all the syntactical delights of Ruby and Haml for your JavaScript. You write in a nice language, but get normal JavaScript at runtime. All whilst having full access to 3rd-party JavaScript libraries (jQuery, PrototypeJS), debugging support (it becomes pure, readable JavaScript), existing support from test suites (it&#8217;s normal JavaScript) and growing support from various text editors (<a href="http://github.com/jashkenas/coffee-script-tmbundle">TextMate</a>, <a href="http://github.com/jashkenas/coffee-script/blob/master/extras/coffee.vim">Vim</a>, <a href="http://github.com/defunkt/coffee-mode">Emacs</a>).</p>
<p>What simple delights?</p>
<p>No trailing semi-colons. No <code>{ some_code() }</code> function/closure brackets. String interpolation. Multi-line strings. Explicit <code>class</code> syntax. Array slicing. An existential ? operator.</p>
<p>Scroll down the <a href="http://jashkenas.github.com/coffee-script/">home page</a> for awesome example after example.</p>
<p>These aren&#8217;t library extensions. This is clean, purposeful syntax.</p>
<p>You can play with the joyful syntax of CoffeeScript on the website. After reading the basic examples on the <a href="http://jashkenas.github.com/coffee-script/">CoffeeScript home page</a>, press &#8220;TRY COFFEESCRIPT&#8221; in the header menu.</p>
<p>As you play with the syntax, the equivalent JavaScript is printed on the right hand side (see image above).</p>
<p>How nice is that syntax? Very.</p>
<h3 id="installing_coffeescript">Installing CoffeeScript</h3>
<ol>
<li>Install NodeJS</li>
<li>Install CoffeeScript</li>
</ol>
<p>For NodeJS (<a href="http://nodejs.org/#download">get latest release URL</a>; using 0.1.31 as 0.1.32 doesn&#8217;t unpack for me):</p>
<pre><code>cd /usr/local/src
wget http://nodejs.org/dist/node-v0.1.31.tar.gz
tar xfv node-v0.1.31.tar.gz
cd node-v0.1.31
./configure
make
sudo make install
</code></pre>
<p>For CoffeeScript (<a href="http://jashkenas.github.com/coffee-script/#installation">get latest release URL</a>):</p>
<pre><code>cd /usr/local/src
wget http://github.com/jashkenas/coffee-script/tarball/0.5.5
tar xfv jashkenas-coffee-script-bcf7b3f.tar.gz
cd jashkenas-coffee-script-bcf7b3f
sudo bin/cake install
</code></pre>
<p>Now test that everything is in place:</p>
<pre><code>$ coffee --version
CoffeeScript version 0.5.5
$ coffee -e "sys: require 'sys'; sys.puts 'hello world\n'"
hello world
</code></pre>
<p>Phew!</p>
<p>Note, in the command-line/on the server, you are using the NodeJS JavaScript environment. It supports the <a href="http://commonjs.org/">CommonJS</a> API for loading modules (normal JavaScript: <code>var sys = require('sys')</code>).</p>
<h3 id="um_but_how_do_i_use_it_in_my_web_app">Um, but how do I use it in my web app?</h3>
<p>Your application source code will have <code>*.coffee</code> files containing your sexy, short CoffeeScript. But at runtime, the browser needs the generated JavaScript.</p>
<p>I&#8217;ve been using the Jonas Nicklas&#8217; <a href="http://github.com/jnicklas/bistro_car">bistro_car</a> gem:</p>
<pre><code>gem install bistro_car
mkdir -p app/scripts
</code></pre>
<p>In your Rails <code>config/environment.rb</code> file, add:</p>
<pre><code>config.gem 'bistro_car'
</code></pre>
<p>And in your layouts, such as <code>app/views/layouts/application.html.erb</code> add to the <code>&lt;head&gt;</code> or the bottom:</p>
<pre><code>&lt;%= coffee_script_bundle %&gt;
</code></pre>
<p>Now you&#8217;re good to go. Add your CoffeeScript files in <code>app/scripts/*.coffee</code> and they will be automatically available as JavaScript.</p>
<h3 id="warning_check_your_version_of_coffeescript">WARNING: Check your version of CoffeeScript</h3>
<p>Check that this hasn&#8217;t happened:</p>
<pre><code>$ coffee --version
CoffeeScript version 0.3.2
$ which coffee
/usr/bin/coffee
</code></pre>
<p>Arrgh, we should be using <code>/usr/local/bin/coffee</code>. <code>bistro_car</code> currently installs the old rubygem-based version of coffee-script; and you might be unlucky to have your $PATH find the wrong one first.</p>
<p>Either delete it (<code>sudo rm /usr/bin/coffee</code> and restart your shell) or make sure <code>/usr/local/bin</code> is earlier in your <code>$PATH</code> than <code>/usr/bin</code>, where RubyGems installed the old, unnecessary version of <code>coffee</code> command.</p>
<h3 id="let8217s_drink_the_coffeescript">Let&#8217;s drink the CoffeeScript</h3>
<p>Create a file <code>app/scripts/application.coffee</code> with contents:</p>
<pre><code>powers: [1,2,3,4].map (i) -&gt; i * i
alert powers
</code></pre>
<p>Load up a view in a browser and see <code>[1,4,9,16]</code>. You win! Throw in some jQuery/PrototypeJS/whatever. Beautiful.</p>
<p>View the source of the page, navigate to <code>public/javascripts/bundle/default.js</code> and you&#8217;ll see the generated source:</p>
<pre class="sh_javascript"><code>(function(){
  var powers;
  powers = [1, 2, 3, 4].map(function(i) {
    return i * i;
  });
  alert(powers);
})();
</code></pre>
<h3 id="the_problem_heroku_doesn8217t_have_coffeescript_installed">The problem: Heroku doesn&#8217;t have CoffeeScript installed</h3>
<p>Heroku is a great place to host apps. Though it doesn&#8217;t have CoffeeScript installed so it cannot dynamically convert the <code>*.coffee</code> files into JavaScript.</p>
<p>If you want to use Heroku I guess we need to perform the conversion locally and deploy it.</p>
<p>But. In development and integration testing I want bistro_car&#8217;s dynamically generated <code>default.js</code>. In production, I need a cached version.</p>
<p>In <code>application.html.haml</code> I use (I can&#8217;t keep pretending I use erb):</p>
<pre class="sh_ruby"><code>- if Rails.env.production?
  = javascript_include_tag "coffeescripts"
- else
  = coffee_script_bundle
</code></pre>
<p>Now we&#8217;re just left with the hassle of automatically generating <code>public/javascripts/coffeescripts.js</code>.</p>
<p>First, a rake task. Second, a git pre-commit hook.</p>
<p>Create <code>lib/tasks/bistro_car.rake</code>:</p>
<pre class="sh_ruby"><code>desc "Generate the cached bundle/default.js file from app/scripts/*.coffee files"
task :bistro_car =&gt; :environment do
  path = "public/javascripts/coffeescripts.js"
  puts "Building *.coffee -&gt; #{path}"
  File.open(path, "w") { |file| file &lt;&lt; BistroCar::Bundle.new('default').to_javascript }
end

file "public/javascripts/coffeescripts.js" =&gt; Dir[File.join(Rails.root, 'app/scripts/*.coffee')] do |t|
  Rake::Task["bistro_car"].invoke
end
</code></pre>
<p>Now you can create <code>coffeescripts.js</code> and add it to the repo with:</p>
<pre><code>rake public/javascripts/coffeescripts.js
git add public/javascripts/coffeescripts.js
git commit -m "Initial bundled coffeescripts file"
</code></pre>
<p>Now create <code>.git/hooks/pre-commit</code>:</p>
<pre class="sh_sh"><code>#!/bin/sh

exec rake public/javascripts/coffeescripts.js
</code></pre>
<p>And make it executable (and <code>git commit</code> will invoke it automatically):</p>
<pre><code>chmod +x .git/hooks/pre-commit
</code></pre>
<p>Phew.</p>
<p>Now, whenever you change a *.coffee script and you are about to commit it, the cached-production-only <code>coffeescripts.js</code> is automatically updated and included in the same commit.</p>
<p>Seems like a clean hack.</p>
<h3 id="summary">Summary</h3>
<p>Why not make a library to do this? Well I&#8217;m hoping there is a better, cleaner way. Perhaps <code>bistro_car</code> can include a rails generator to package these bits and pieces itself, if my approach happens to be the best way.</p>
<p>Nonetheless, let history record that CoffeeScript is very cool though in the world of Heroku living with it is non-trivial at the moment.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/06/01/validate-and-save-your-ruby-in-textmate-with-secret-rubinus-superpowers/' rel='bookmark' title='Permanent Link: Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers'>Validate and Save your Ruby in TextMate &#8211; with secret Rubinus superpowers</a> <small>In some TextMate bundles, if you save a file it...</small></li><li><a href='http://drnicwilliams.com/2010/05/28/showcase-of-coffeescript-2-5-mins-for-your-next-dev-group-meeting/' rel='bookmark' title='Permanent Link: Showcase of CoffeeScript &#8211; 2.5 mins for your next Dev Group meeting'>Showcase of CoffeeScript &#8211; 2.5 mins for your next Dev Group meeting</a> <small> If you are giving an &#8220;Introduction to CoffeeScript&#8221; talk...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Customized Google Forms</title>
		<link>http://drnicwilliams.com/2010/02/25/customized-google-forms/</link>
		<comments>http://drnicwilliams.com/2010/02/25/customized-google-forms/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 11:30:24 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Trick]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=688</guid>
		<description><![CDATA[Google Forms are a great, free way to collect information from anyone, stored directly into a Google Spreadsheet, and then have Google notify you each time a form is submitted (optionally). The downside is that you can only use one of their pre-packaged themes. You can&#8217;t have your company logo and corporate &#8220;look&#8221;. Pooey to [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/' rel='bookmark' title='Permanent Link: Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;'>Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;</a> <small> Got a simple app you want to build? Allocate...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20100225-rm11rdpj6qib6ukbwdi87ewd76.preview.jpg" alt="Google Form Customized" style="float: right; width: 200px"/></p>
<p>Google Forms are a great, free way to collect information from anyone, stored directly into a Google Spreadsheet, and then have Google notify you each time a form is submitted (optionally). The downside is that you can only use one of their pre-packaged themes. You can&#8217;t have your company logo and corporate &#8220;look&#8221;.</p>
<p>Pooey to Google, we say. So we wrote <a href="http://github.com/mocra/custom_google_forms">custom_google_forms</a>.</p>
<p>Want to truly customized Google Forms? Fork this repository, customize the CSS, DOM and images, and deploy to Heroku. You can then host/customize any number of Google Forms.</p>
<p>For example, here is an original <a href="http://spreadsheets.google.com/a/mocra.com/viewform?formkey=dFo0LXQyYmlEV2dXcVJ6WjRweW9vRnc6MA">bare Google Form</a> and here is a <a href="http://forms.mocra.com/railsdev">fully customized version</a>, including form validation and thank you page.</p>
<p>It&#8217;s fully a dynamic, thin layer on top of Google Forms. If you change your Google Form, your custom form application automatically changes.</p>
<h2 id="how_to_use_google_forms">How to use Google Forms?</h2>
<p>Perhaps read <a href="http://docs.google.com/support/bin/answer.py?hl=en&amp;answer=87809">this docco</a>? Essentially if you can access Google Spreadsheets, you can create a Google Form (which automatically creates and updates a Google Spreadsheet based on the fields and form submissions).</p>
<h2 id="fork_and_customize">Fork and Customize</h2>
<p>It&#8217;s really simple to play with and customize Google Forms. Clone the <a href="http://github.com/mocra/custom_google_forms">GitHub project</a> and fire up the Rails server:</p>
<pre><code>gem install github
cd ~/Sites
gh clone mocra/custom-google-forms yourdomain-google-forms
cd yourdomain-google-forms
script/server
</code></pre>
<p>Go to <a href="http://localhost:3000/google_forms/new">http://localhost:3000/google_forms/new</a> and add a Google Form:</p>
<p><img src="http://img.skitch.com/20100225-msfc5a8gk5rnm5pm7qdy9fd6x6.jpg" alt="My Google Forms - New" style="width: 100%"/></p>
<p>The &#8220;Slug&#8221; is the URL path people will follow. That is, a slug &#8220;railsdev&#8221; maps to <a href="http://forms.mocra.com/railsdev">http://forms.mocra.com/railsdev</a>.</p>
<p>The &#8220;Form Key&#8221; field takes either the <a href="http://spreadsheets.google.com/a/mocra.com/viewform?hl=en&amp;formkey=dFo0LXQyYmlEV2dXcVJ6WjRweW9vRnc6MA">Form URL</a> or just the formkey parameter (e.g. dFo0LXQyYmlEV2dXcVJ6WjRweW9vRnc6MA) from when you view the live form.</p>
<p>Press &#8220;Create&#8221; and follow the slug url to view your Google Form through your own customized style.</p>
<p>Well, initially you&#8217;ll see the Mocra style. Let&#8217;s fix that.</p>
<h1 id="default_theme">Default Theme</h1>
<p>First, fork the github repository so that you can push your style changes to your own repo.</p>
<pre><code>gh fork
mate public/stylesheets/style.css
</code></pre>
<p>Now, edit <a href="http://github.com/mocra/custom_google_forms/blob/master/public/stylesheets/style.css">public/stylesheets/style.css</a> to your tastes.</p>
<p>Please don&#8217;t reuse our style. Aside from you looking a bit silly having the :mocra logo at the top, it would be weird if your forms looked like our forms. I guess you might as well have used the default Google Form themes?</p>
<h1 id="heroku_deployment">Heroku Deployment</h1>
<p>Let&#8217;s not get fancy, let&#8217;s just deploy your fork to Heroku. It&#8217;s free. It&#8217;s simple. You&#8217;ll be done in two minutes.</p>
<p>To get your copy of the application deployed to <a href="http://heroku.com">heroku</a>:</p>
<pre><code>gem install heroku
heroku create yourdomain-google-forms
git push heroku master
heroku rake db:migrate
</code></pre>
<p>Two optional environment variables:</p>
<pre><code>heroku config:add GOOGLE_ANALYTICS='YOURCODE'
</code></pre>
<p>If specified, Google Analytics will be included on all pages (including the custom Google Forms page).</p>
<pre><code>heroku config:add EXPECTED_DOMAIN='some.yourdomain.com'
</code></pre>
<p>If specified, &#8216;yourdomain-google-forms.heroku.com/someform&#8217; automatically redirects to &#8216;some.domain.com/someform&#8217;. </p>
<p>For example, for http://forms.mocra.com we used:</p>
<pre><code>heroku config:add GOOGLE_ANALYTICS='UA-5370510-4'
heroku config:add EXPECTED_DOMAIN='forms.mocra.com'
</code></pre>
<h1 id="getting_started">Getting Started</h1>
<p>Once deployed, go to the /google_forms/new URL and add your first form. Once it is validated and added, you can start using it using the links shown.</p>
<h1 id="summary">Summary</h1>
<p>Yay for free, customized Google Forms! Yay for free Heroku hosting!</p>
<p>Bonus: you can configure your Google Forms/Spreadsheet to notify you when new forms are submitted. That&#8217;s handy.</p>
<p>Thanks to Odin Dutton, our resident designer at Mocra, who did a great job applying our new theme to the Google Forms DOM structure. It&#8217;s wonderful having him on the team!</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/' rel='bookmark' title='Permanent Link: Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;'>Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;</a> <small> Got a simple app you want to build? Allocate...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2010/02/25/customized-google-forms/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>First look at rails 3.0.pre</title>
		<link>http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/</link>
		<comments>http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 04:05:16 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=630</guid>
		<description><![CDATA[This article is out of date in some aspects. See comments, and perhaps this summary of reading materials about Rails 3. Today I had my first look at rails 3.0.pre and below are the sequence of steps I had to take to create a rails 3.0.pre application, and get it&#8217;s generators to work. Why was [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/' rel='bookmark' title='Permanent Link: Rails themes can remember things'>Rails themes can remember things</a> <small>I was getting annoyed at having to remember all the...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<div class="notice">
<p>This article is out of date in some aspects. See <a href="http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/#comments">comments</a>, and perhaps this summary of <a href="http://mediumexposure.com/rails-3-reading-material/">reading materials</a> about Rails 3.</p>
</div>
<p><img src="http://img.skitch.com/20091103-q3w8qjy8wmr3e9wasjqc95nf6g.jpg" alt="3.pre" style="float: right" /></p>
<p>Today I had my first look at rails 3.0.pre and below are the sequence of steps I had to take to create a rails 3.0.pre application, and get it&#8217;s generators to work.</p>
<p>Why was I looking at the top-secret, yet open-source Rails 3.0? Their generators are being migrated over to Thor and I wanted to see them in action. I was thinking I might migrate newgem to use Thor too.</p>
<p>Here&#8217;s a quick poke around of getting started and interesting things I found. Any hiccups and workarounds are meant as a guide to pre-pre-3.0 users/developers and not as a criticism of rails-core. Rails 3.0 is looking shiny and awesome.</p>
<p>NOTE: Since this is a &#8220;how to install and use&#8221; rails 3.0 edge, which is still in heavy development, this set of instructions might break. Let&#8217;s hope not.</p>
<h2 id="getting_started">Getting Started</h2>
<p>As of today, you cannot install 3.0.pre from rubygems [1]. So, let&#8217;s install them from source. Which is handy, you might like to patch something.</p>
<pre><code>$ cd ~/gems
$ git clone git://github.com/rails/rails.git
use_ruby_191 *
</code></pre>
<p>[*] If you are on OS X Snow Leopard I think you can ignore this. Otherwise, since you don&#8217;t have the 3.0.pre gems installed, you&#8217;re about to hit bump #1. Ruby 1.8.6 doesn&#8217;t have <code>Symbol#to_proc</code> but it&#8217;s required to create a rails app. This means you&#8217;ll need to be able to switch to another version of ruby temporarily if you&#8217;re on ruby 1.8.6 [2].</p>
<pre><code>cd ~/Sites
ruby ~/gems/rails/railties/bin/rails
</code></pre>
<p>Oooh, look at all the new options! Some new ones are:</p>
<pre><code>-F, [--freeze]             # Freeze Rails in vendor/rails from the gems
-O, [--skip-activerecord]  # Skip ActiveRecord files
-T, [--skip-testunit]      # Skip TestUnit files
-J, [--skip-prototype]     # Skip Prototype files
</code></pre>
<p>The <code>-D, --with-dispatchers</code> flags have been removed. <code>--freeze</code> isn&#8217;t new, but <code>-F</code> is.</p>
<p>So, to create an app, I dutifully used:</p>
<pre><code>ruby ~/gems/rails/railties/bin/rails edgerailsapp -F
</code></pre>
<p>BAM! Fail. The -F option to freeze/vendor rails fails without the gems installed. So don&#8217;t use it.</p>
<pre><code>ruby ~/gems/rails/railties/bin/rails edgerailsapp
ln -s ~/gems/rails vendor/rails
</code></pre>
<p>If you&#8217;re on Windows without the symlink command <code>ln</code>, then copy the downloaded rails source into <code>vendor/rails</code>.</p>
<h3 id="fetch_rails8217_dependencies">Fetch Rails&#8217; dependencies</h3>
<p>Rails 3.0 source uses the new bundler project to describe its own dependencies. From <a href="http://litanyagainstfear.com/blog/2009/10/14/gem-bundler-is-the-future/">Nick Quaranto&#8217;s article on bundler</a>, get the latest:</p>
<pre><code>cd ~/gems
git clone git://github.com/wycats/bundler
cd bundler
sudo rake install
</code></pre>
<p>Now, back in your app, you need to install some rails dependencies here too. It&#8217;s a good chance to see how you&#8217;ll bundle gem dependencies in the future.</p>
<pre><code>$ cd ~/Sites/edgerailsapp
</code></pre>
<p>Change the <code>Gemfile</code> in your project to the following:</p>
<pre><code>gem "rack",          "1.0.1"
gem "rack-mount",    :git =&gt; "git://github.com/rails/rack-mount.git"
gem "rack-test",     "~&gt; 0.5.0"
gem "erubis",        "~&gt; 2.6.0"
gem "arel",          :git =&gt; "git://github.com/rails/arel.git"
gem "sqlite3-ruby"
gem "rails", "3.0.pre", :git =&gt; "git://github.com/rails/rails.git"
</code></pre>
<p>Welcome to the future of gem dependencies for rails apps. Ultimately you won&#8217;t need to manually add these lines yourself. When rails is distributed as gems it will automatically install these for you, I assume/hope/guess. But for today, you seem to need them.</p>
<p>Now locally (within your app) install these gems:</p>
<pre><code>$ gem bundle
</code></pre>
<p>If you get &#8220;can&#8217;t convert Pathname into String&#8221; then revert to ruby 1.8.X and reinstall bundler into your 1.8 gem cache.</p>
<p>Phew. Ooh, my god. Phew. Only now will <code>script/generate</code> work.</p>
<pre><code>$ script/generate
</code></pre>
<p>For me, this outputs:</p>
<pre><code>Please select a generator.
Builtin: app, controller, generator, helper, integration_test, mailer, metal, migration, model, model_subclass, observer, performance_test, plugin, resource, scaffold, scaffold_controller, session_migration, stylesheets.
Others: app_layout:app_layout, check_migration_version:check_migration_version, home_route:home_route.
</code></pre>
<p>The &#8220;Builtin&#8221; generators are the latest and greatest in Thor technology. Rails 3.0 no longer uses its own generator but is built upon Thor.</p>
<p>For example, our old favourite <code>model</code> generator works thusly:</p>
<pre><code>$ script/generate model Post title:string --no-fixture
    invoke  active_record
    create    db/migrate/20091103030824_create_posts.rb
    create    app/models/post.rb
    invoke    test_unit
    create      test/unit/post_test.rb
</code></pre>
<p>Interestingly, <code>--no-fixture</code> isn&#8217;t mentioned in the usage information for <code>script/generate model</code>. It mentions the <code>--fixture</code> flag, but I had to guess that <code>--no-fixture</code> was also supported.</p>
<p>Hmm, I want to use rspec. So, let&#8217;s destroy these files:</p>
<pre><code>$ script/destroy model Post title:string
      invoke  active_record
.../vendor/gems/dirs/rails/railties/lib/rails/generators/active_record.rb:14:in
  `next_migration_number': uninitialized constant ActiveRecord::Base (NameError)
</code></pre>
<p>Oh well.</p>
<p>What if I wanted to run rspec and cucumber generators, for example, against an edge rails app?</p>
<h2 id="rails_2_generators">Rails 2 generators</h2>
<p>The &#8220;Others&#8221; generators are my own local generators from <code>~/.rails/generators</code>. Amusingly, instead of <code>app_layout</code> it is called <code>app_layout:app_layout</code>. Not surprisingly at all, if I try to run the rails 2 generator it fails:</p>
<pre><code>$ script/generate app_layout:app_layout
[WARNING] Could not load generator at "/Users/drnic/.rails/generators/app_layout/app_layout_generator.rb". Error: uninitialized constant Rails::Generator
Could not find generator app_layout:app_layout.
</code></pre>
<p>Poop. </p>
<p>Note, I have rspec, rspec-rails and cucumber gems installed locally but I cannot see their rails generators above. Rails 3 doesn&#8217;t look for generators in the same way and old Rails 2 generators don&#8217;t work anymore.</p>
<p>That&#8217;s the news: every rails 2 generator is broken. </p>
<p>When I start to migrate some of mine I&#8217;ll post about it. In the meantime, <a href="http://twitter.com/josevalim">José Valim</a> has written some introduction thoughts on <a href="http://blog.plataformatec.com.br/2009/07/creating-your-own-generators-with-thor/">using Thor as a generator</a>.</p>
<p>You can also probably learn about how to write rails 3.0 generators by looking at the source code for the new generators like <a href="http://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/app/app_generator.rb">rails</a>, model (see <a href="http://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/model/model_generator.rb">main</a> and  <a href="http://github.com/rails/rails/blob/master/railties/lib/rails/generators/test_unit/model/model_generator.rb">test_unit</a>), and <a href="http://github.com/rails/rails/blob/master/railties/lib/rails/generators/rails/resource/resource_generator.rb">scaffold/resource</a>.</p>
<p>Finally, José Valim has a <a href="http://github.com/josevalim/third_rails">sample Rails 3 app</a> with some vendored generators in it.</p>
<p>These are the things I&#8217;m researching now.</p>
<h2 id="summary">Summary</h2>
<p>This article is long, mostly because rails 3.0.pre hasn&#8217;t been released as a set of RubyGems. If it had, then all the dependencies would be installed automatically.</p>
<p>It also introduces gem/plugin writers to the first upgrade issue: your current generators are neither discovered nor work by a rails 3.0 app. We&#8217;re all clever cookies, so here&#8217;s hoping we can figure out the upgrade path and that it&#8217;s simple enough to not be the topic of Dan Brown&#8217;s next book.</p>
<h2 id="footnotes">Footnotes</h2>
<p>[1] Two portions of rails 3.0.pre are available as pre-release gems: activesupport (which is now very modularised and only loads up the parts that you require) and activemodel (which is shiny and new and hence completely safe for rails-core to release).</p>
<p>[2] There are two popular ways to have easy, non-intrusive access to alternate versions of ruby: <a href="http://www.rubyinside.com/rvm-ruby-version-manager-2347.html">rvm</a> and <a href="http://blog.thinkrelevance.com/2009/7/29/ruby-switcher-working-with-multiple-ruby-versions-has-never-been-this-easy">ruby_switcher.sh</a>.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/' rel='bookmark' title='Permanent Link: Rails themes can remember things'>Rails themes can remember things</a> <small>I was getting annoyed at having to remember all the...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Rails themes can remember things</title>
		<link>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/</link>
		<comments>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:23:26 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[install_theme]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=604</guid>
		<description><![CDATA[I was getting annoyed at having to remember all the csspath/xpath expressions for a theme I reused in a new project. So, install_theme now helps each theme folder remember the previously used settings. gem install install_theme # version 0.7.0+ install_theme path/to/rails_app path/to/template #content_box \ --partial "header:#header h2" \ --partial sidebar:#sidebar" Now, the next time you [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>I was getting annoyed at having to remember all the csspath/xpath expressions for a theme I reused in a new project.</p>
<p>So, install_theme now helps each theme folder remember the previously used settings.</p>
<pre>
gem install install_theme  # version 0.7.0+
install_theme path/to/rails_app path/to/template #content_box \
      --partial "header:#header h2" \
      --partial sidebar:#sidebar"
</pre>
<p>Now, the next time you apply that same theme to another project you don&#8217;t need to mention &#8220;#content_box&#8221; or use the <code>--partial</code> flags:</p>
<pre>
install_theme path/to/another_rails_app path/to/template
</pre>
<h3>How?</h3>
<p>If you squint your eyes just right, you&#8217;ll notice that your original template folder now has an <code>install_theme.yml</code> file. It contains your original settings. You can imagine for yourself how the rest of the &#8220;themes can remember things&#8221; magic might work.</p>
<h3>Templates &#8220;For Ruby on Rails&#8221;</h3>
<p>If you are a template maker, you can now easily make your HTML template &#8220;For Ruby on Rails&#8221; by including an <code>install_theme.yml</code> file. Think of the children.</p>
<h3>Major change</h3>
<p>I changed the order of the first two arguments. In future, the path/to/template will be optional. Why? Imagine if each theme you ever used was cached in <code>~/.install_theme/themes</code> and you could select a theme from a list or by <code>--theme theme_name</code>. That seems neat.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/10/07/rails-themes-can-remember-things/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Install any HTML theme/template into your Rails app</title>
		<link>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/</link>
		<comments>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 23:55:58 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[install_theme]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=580</guid>
		<description><![CDATA[Have you ever even bothered to Google for &#8220;rails html template&#8221;? There are millions of &#8220;WordPress themes&#8221; you can download for free or less than $100, a thousand times more static HTML templates, but never any category of template called &#8220;Ruby on Rails theme&#8221;. 24 millions results for Googling single column html theme. So we&#8217;re [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://img.skitch.com/20091005-8at43u9msix8pbky8p2ft5ejj3.preview.jpg" alt="theme applied and menu update" style="float: right; display: inline; margin: 0 0 2px 7px; width: 40%"/></p>
<p>Have you ever even bothered to Google for &#8220;rails html template&#8221;? There are millions of &#8220;WordPress themes&#8221; you can download for free or less than $100, a thousand times more static HTML templates, but never any category of template called &#8220;Ruby on Rails theme&#8221;. 24 millions results for Googling <a href="http://www.google.com/search?hl=en&amp;q=single+column+html+theme">single column html theme</a>.</p>
<p>So we&#8217;re only left with HTML templates. Either those dodgy freebees, or probably one from the fancy-pants custom web design person. But how do we install them to our Rails apps?</p>
<p>I don&#8217;t know. It sucks. And it takes more time than it should. Here&#8217;s my idea &#8211; a tool to install any HTML template into your Rails app. To treat any HTML template as if it was a &#8220;Ruby on Rails HTML Template&#8221;.</p>
<p>So I&#8217;ve started to try and make any &#8220;HTML Template&#8221; into a &#8220;Ruby on Rails Template&#8221; with the helper app <a href="http://github.com/drnic/install_theme">install_theme</a>.</p>
<h3 id="what8217s_it_do">What&#8217;s it do?</h3>
<p>Take any HTML/CSS template, <code>install_theme</code> will install the various assets into the appropriate places of your Rails application, and convert the main sample page of the template into your app/views/layouts/application.html.erb (or .haml). Easy peasy.</p>
<p>Instead of taking a few hours or a day to install a template into your Rails app, the most part now just takes a minute or two. Into either ERB or Haml. Repeatable if the original HTML/CSS template changes.</p>
<p>Consider a free admin template <a href="http://www.oswd.org/design/information/id/2312">Refreshed</a> [<a href="http://www.oswd.org/design/download/id/2312">download</a>].</p>
<p><a href="http://skitch.com/drnic/nb731/refreshed-theme"><img src="http://img.skitch.com/20091005-teh6s3axcj275q8tx7tjkwu3ht.jpg" alt="refreshed theme" /></a></p>
<p>Installing a theme for fun and profit into a fresh rails app:</p>
<pre>$ gem install install_theme
$ rails my_app
$ cd my_app
$ install_theme . path/to/theme/folder ".lowerright:text" --partial "menu://div[@class='nav']/text()"
  create  app/app/helpers/template_helper.rb
  create  app/controllers/original_template_controller.rb
  create  app/helpers/template_helper.rb
  create  app/views/layouts/_menu.html.erb
  create  app/views/layouts/application.html.erb
  create  app/views/original_template/index.html.erb
  create  public/images/footer.png
  ...
  create  public/stylesheets/style.css

Your theme has been installed into your app.
</pre>
<p>When you launch the app, it will be instantly themed. The section of the original template with DOM path <code>.lowerright</code> will be removed and replaced by your rendered actions.</p>
<p>The <code>--partial</code> flag converts a section into a partial template (or via <code>content_for</code> helper). More on this in a minute.</p>
<p>Note: the example above uses both CSS path and XPath expressions. For each section of the template you want to convert to a partial you use then <code>--partial</code> flag. The argument is &#8220;label:xpath&#8221; or &#8220;label:csspath&#8221;. So either <code>--partial "header://div[@id='header']/h2"</code> or <code>--partial "header:#header h2"</code>.</p>
<p>Here are the content and partial selections using CSSpath:</p>
<pre>$ install_theme . path/to/theme/folder ".lowerright:text" --partial "menu:.nav:text"
</pre>
<p><img src="http://img.skitch.com/20091005-e7wbqw6m198qtbdbe9y3h1s7j2.jpg" alt="refreshed theme - identifying partials" /></p>
<p>Here are the content and partial selections using XPath:</p>
<pre>$ install_theme . path/to/theme/folder "//div[@class='lowerright']/text()" --partial "menu://div[@class='nav']/text()"
</pre>
<p><img src="http://img.skitch.com/20091005-x673pwf9bshi4sbjhxa91ksenj.jpg" alt="refreshed theme - identifying partials" /></p>
<h2 id="overriding_the_theme_partials">Overriding the theme partials</h2>
<p>Now that you&#8217;ve selected portions of the template to be dynamically changeable partials, how do you change them?</p>
<ol>
<li>Use <code>&lt;% content_for :menu do %&gt; ... &lt;% end %&gt;</code> from any view template</li>
<li>Create a <code>_menu.html.erb</code> partial in your controller&#8217;s views folder, e.g. <code>app/views/posts/_menu.html.erb</code></li>
<li>Modify the <code>_menu.html.erb</code> partial in the <code>app/views/layouts</code> folder. This is the default source.</li>
</ol>
<p>The original template&#8217;s menu items (home, about, forum, etc) have been moved into <code>app/views/layouts/_menu.html.erb</code>. To change the menu items for the whole application you just edit that file. For this template, it will look like:</p>
<pre>&lt;a href="#"&gt;home&lt;/a&gt;
&lt;a href="#"&gt;about&lt;/a&gt;
&lt;a href="#"&gt;forum&lt;/a&gt;
&lt;a href="#"&gt;design&lt;/a&gt;
&lt;a href="#"&gt;info&lt;/a&gt;
&lt;a href="#"&gt;contact&lt;/a&gt;
</pre>
<p>This is the extracted content of the <code>.nav</code> DOM element. You now modify it to have the same DOM structure, a bunch of links, and you&#8217;ll get the same theme output.</p>
<p>Let&#8217;s change the menu across the entire application. Edit <code>app/views/layouts/_menu.html.erb</code>:</p>
<pre>&lt;%= link_to "home", "/" %&gt;
&lt;%= link_to "posts", posts_path %&gt;
&lt;%= link_to "new post", new_post_path %&gt;
</pre>
<p>If you wanted to change the menu for all actions in the posts controller, then create a similar partial in <code>app/views/posts/_menu.html.erb</code>.</p>
<p>If you wanted to change the menu for a specific action, then use <code>content_for</code> in your view:</p>
<pre>&lt;% content_for :menu do: %&gt;
  &lt;a href="/"&gt;home&lt;/a&gt;
  &lt;a href="/login"&gt;sign in&lt;/a&gt;
  &lt;a href="/signup"&gt;create account&lt;/a&gt;
&lt;% end %&gt;
</pre>
<h2 id="haml">Haml</h2>
<p>I use Haml and I like it. <code>install_theme</code> automatically detects if you are using Haml, and generates haml HTML views and sass CSS files.</p>
<pre>$ gem install drnic-haml --source http://gemcutter.org  # see below
$ rails my_haml_app
$ cd my_haml_app
$ haml --rails .
$ install_theme . path/to/theme/folder ".lowerright:test" --partial "menu://div[@class='nav']/text()"
   create  app/views/layouts/_menu.html.haml
   create  app/views/layouts/application.html.haml
   create  app/views/original_template/index.html.haml
   create  public/stylesheets/sass/style.sass
</pre>
<p>NOTE: there is a new version of haml&#8217;s html2haml (which install_theme uses) coming that fixes many bugs. In the short term, use the drnic-haml above.</p>
<h2 id="where8217d_my_original_content_go">Where&#8217;d my original content go?</h2>
<p>Your template might include examples of how a table looks, or a form, or pagination. It would good if they weren&#8217;t lost on the chopping floor.</p>
<p>The original template&#8217;s contents are stored at <code>app/views/original_templates/index.html.erb</code> and viewable at <a href="http://localhost:3000/original_template">http://localhost:3000/original_template</a></p>
<p>That means you can now copy + paste any sample HTML snippets as you need them.</p>
<h2 id="how_it_works">How it works?</h2>
<p>Look inside the generated <code>application.html.erb</code> file and you&#8217;ll see the following for each named partial:</p>
<pre>&lt;%= yield(:menu) || render_or_default('menu') %&gt;
</pre>
<p>The <code>yield(:menu)</code> enables the <code>content_for</code> helper to override the partials.</p>
<p>The <code>render_or_default</code> helper finds the appropriate partial to use (see app/helpers/template_helper.rb for source).</p>
<h2 id="the_future">The Future</h2>
<p>Let me know if anyone else thinks this is useful, and what other fun things you think it could do.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Cucumber: building a better World (object)</title>
		<link>http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/</link>
		<comments>http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 02:48:48 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=513</guid>
		<description><![CDATA[How to write helper libraries for your Cucumber step definitions and how to upgrade your support libraries from Cucumber 0.2 to 0.3 (released today). In cucumber, each scenario step in a .feature file matches to a Given, When, Then step definition. The step definitions are normal Ruby code. First class, bonnified, honky-tonk Ruby code. And [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/10/07/hash-bang-cucumber/' rel='bookmark' title='Permanent Link: hash bang cucumber'>hash bang cucumber</a> <small>I don&#8217;t know if this is a good idea or...</small></li><li><a href='http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/' rel='bookmark' title='Permanent Link: Testing outbound emails with Cucumber'>Testing outbound emails with Cucumber</a> <small> My testimonial for Cucumber still stands even in 2009....</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><em>How to write helper libraries for your Cucumber step definitions and how to upgrade your support libraries from Cucumber 0.2 to 0.3 (released today).</em></p>
<p>In cucumber, each scenario step in a <em>.feature</em> file matches to a <code>Given</code>, <code>When</code>, <code>Then</code> step definition. The step definitions are normal Ruby code. First class, bonnified, honky-tonk Ruby code. And what&#8217;s the one thing we love to do to Ruby code on a rainy Sunday afternoon? Refactor it. Turn messy code into readable &#8220;return in 50 years, on the time capsule, and get back to work quickly&#8221; code.</p>
<p>In Cucumber we use a special, until-now unknown, magic technique for refactoring step definitions. They are called &#8220;Ruby methods&#8221;. Oooh, feel the magic. You take some code in a step definition and you refactor it into a method. And you&#8217;re done. For example:</p>
<pre>When /I fill in the Account form/ do
  fill_in("account_name", :with => "Mocra")
  fill_in("account_abn", :with => "12 345 678 901")
  click_button("Submit")
end
</pre>
<p>Could be refactored into:</p>
<pre>When /I fill in the Account form/ do
  fill_in_account_form
end

def fill_in_account_form
  fill_in("account_name", :with => "Mocra")
  fill_in("account_abn", :with => "12 345 678 901")
  click_button("Submit")
end
</pre>
<p>Good work. Or is it? No, we&#8217;ve done something a little naughty. We&#8217;ve polluted the global object space with our method and turns out it just isn&#8217;t necessary. There&#8217;s a nicer way and a clean idiom for how/where to write helper methods.</p>
<p>Annoyingly, that idiom broke with the release of Cucumber 0.3. So I&#8217;ll introduce both so you can fix any bugs that you spot and know how to fix them.</p>
<p>The solution is to understand the existence of the World object and the clean technique for writing <em>features/support/foobar_helpers.rb</em> libraries of helper methods.</p>
<h3 id="introducing_the_world_object">Introducing the World object</h3>
<p>To ensure that each cucumber scenario starts with a clean slate, your scenarios are run upon a blank <code>Object.new</code> object. Or in a Rails project its a new Rails test session <code>ActionController::IntegrationTest</code>.</p>
<p>These are called <code>World</code> objects (see <a href="http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world">cucumber wiki</a>). You pass in a specific World object you&#8217;d like to use, else it defaults to <code>Object.new</code> For a Rails project, you&#8217;re using <code>Cucumber::Rails::World.new</code> for your world object each time, which is a subclass of <code>ActionController::IntegrationTest</code>.</p>
<p>The benefit of a World object starting point for each scenario is that you can add methods to it, that won&#8217;t affect the rest of the Ruby world you live in: which will be the Cucumber runner. That is, you cannot accidently blow up Cucumber.</p>
<h3 id="extending_the_world_object">Extending the World object</h3>
<p>Step 1, put methods in a module. Step 2, add the module to your World object.</p>
<p>So that we&#8217;re all extending Cucumber in the same way, there is a folder for where your helper methods should be stored, and a programming idiomatic way to do it. It has changed slight from Cucumber 0.2 to 0.3 so I&#8217;ll show both.</p>
<p>For our helper method <code>fill_in_account_form</code> above:</p>
<ol>
<li>Create <em>features/support/form_submission_helpers.rb</em> (its automatically loaded)</li>
<li>Wrap the helper method in a module <code>module FormSubmissionHelpers ... end</code></li>
<li>Tell Cucumber to include the module into each World object for each Scenario</li>
</ol>
<p>In Cucumber 0.3+ your complete helper file would look like:</p>
<pre>module FormSubmissionHelpers
  def fill_in_account_form
    fill_in("account_name", :with => "Mocra")
    fill_in("account_abn", :with => "12 345 678 901")
    click_button("Submit")
  end
end
World(FormSubmissionHelpers)
</pre>
<p>For Cucumber 0.2 your complete helper file might have looked like:</p>
<pre>module FormSubmissionHelpers
  def fill_in_account_form
    fill_in("account_name", :with => "Mocra")
    fill_in("account_abn", :with => "12 345 678 901")
    click_button("Submit")
  end
end
World do |world|
  world.extend FormSubmissionHelpers
end
</pre>
<p>Where the difference is the last part of the file. This mechanism is deprecated and results in the following error message after upgrading to Cucumber 0.3:</p>
<pre>/Library/Ruby/Gems/1.8/gems/cucumber-0.3.0/bin/../lib/cucumber/step_mother.rb:189:in `World': You can only pass a proc to #World once, but it's happening (Cucumber::MultipleWorld)
in 2 places:

vendor/plugins/cucumber/lib/cucumber/rails/world.rb:72:in `World'
vendor/plugins/email-spec/lib/email_spec/cucumber.rb:18:in `World'
</pre>
<h3 id="summary">Summary</h3>
<p>Refactor step definitions. Put it in <em>features/support/&#8230;_helpers.rb</em> files, inside modules that are assigned to the World object.</p>
<h3>And a word from our sponsor</h3>
<p>Starting a new Rails project and need the team that is up-to-date with all the latest and greatest gadgetry, plugins and gems, styles and processes for enterprise and web2.0 web applications? <a href="http://mocra.com/contact">Ask us at Mocra</a>.</p>
<p>Need professionals to help your Rails project burst over the finish line? <a href="http://mocra.com/contact">Ask us at Mocra</a>.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/10/07/hash-bang-cucumber/' rel='bookmark' title='Permanent Link: hash bang cucumber'>hash bang cucumber</a> <small>I don&#8217;t know if this is a good idea or...</small></li><li><a href='http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/' rel='bookmark' title='Permanent Link: Testing outbound emails with Cucumber'>Testing outbound emails with Cucumber</a> <small> My testimonial for Cucumber still stands even in 2009....</small></li><li><a href='http://drnicwilliams.com/2008/10/31/newgem-100-all-thanks-to-cucumber/' rel='bookmark' title='Permanent Link: newgem 1.0.0 all thanks to Cucumber'>newgem 1.0.0 all thanks to Cucumber</a> <small>The New Gem Generator (newgem) was exciting, moderately revolutionary, and...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Easy scheduling by location, tasks and people &#8211; a case study of a client application from Mocra</title>
		<link>http://drnicwilliams.com/2009/04/06/easy-scheduling-by-location-tasks-and-people-a-case-study-of-a-client-application-from-mocra/</link>
		<comments>http://drnicwilliams.com/2009/04/06/easy-scheduling-by-location-tasks-and-people-a-case-study-of-a-client-application-from-mocra/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 07:02:22 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=504</guid>
		<description><![CDATA[UPDATE: Orchestrate was reported in TechCrunch Several years ago Andy Wright uncovered a problem. Small and large businesses can have the same problem: orchestrating to get a qualified person to perform a job. Who&#8217;s got the skills? Who&#8217;s available? What tasks have you offered/sold to your customers? Its hard enough getting customers and finding great [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/16/making-a-pretty-firefox-beta-application-icon/' rel='bookmark' title='Permanent Link: Making a pretty Firefox Beta application icon'>Making a pretty Firefox Beta application icon</a> <small> Here&#8217;s the problem: I install OS X Firefox 3.6b2...</small></li><li><a href='http://drnicwilliams.com/2009/06/30/refer-us-a-client-for-fun-and-profit/' rel='bookmark' title='Permanent Link: Refer us a client for fun and profit'>Refer us a client for fun and profit</a> <small>There&#8217;s only so many hours in the day and only...</small></li><li><a href='http://drnicwilliams.com/2007/06/09/smart-people-doing-smart-things-in-netherlands-rubyenrails-2007/' rel='bookmark' title='Permanent Link: Smart people doing smart things in Netherlands &#8211; RubyEnRails 2007'>Smart people doing smart things in Netherlands &#8211; RubyEnRails 2007</a> <small>Summary: click to select Photo by Thijs van der Vossen,Fingertips...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://orchestrateapp.com"><img width="250" src="http://orchestrateapp.com/images/content/home_page_illustration.png" class="alignright"/></a></p>
<p><strong>UPDATE:</strong> Orchestrate was reported in <a href="http://www.techcrunch.com/2009/04/08/orchestrate-saas-task-management-for-service-and-maintenance-businesses/">TechCrunch</a></p>
<p>Several years ago <a href="http://elevensoft.com/">Andy Wright</a> uncovered a problem. Small and large businesses can have the same problem: orchestrating to get a qualified person to perform a job. Who&#8217;s got the skills? Who&#8217;s available? What tasks have you offered/sold to your customers? </p>
<p>Its hard enough getting customers and finding great staff/contractors, but then you might spend many nervous hours juggling demand against availability. Then you need to keep a history of jobs and tasks performed. Did your staff do the work? Does anyone need to follow up?</p>
<p>The same types of jobs, the same set of qualified staff, the same process of orchestration. Every day. Bah. Fortunately Andy invested the last several years into solution towards automation: <a href="http://orchestrateapp.com">Orchestrate</a>. </p>
<p><a href="http://orchestrateapp.com/tour.html"><img src="http://orchestrateapp.com/images/content/tour_images/schedule_popup_large.jpg" width="550"></a></p>
<p>I&#8217;m in love with this application because <a href="http://mocra.com">Mocranites</a> Bo Jeanes, Ryan Bigg, Jack Chen and myself helped it mature over the last 6 months into a production-ready, enterprise scaling mega app. From adolescence to adulthood.</p>
<p>Orchestrate has now graduated &#8220;Rails Development University&#8221; and <strong>gone live</strong>, after a two month stint in beta.</p>
<p>The design for Orchestrate was done by <a href="http://hicksdesign.co.uk/">Jon Hicks</a>, world famous as the creator of the FireFox logo. The original code base was created by <a href="http://jonathanleighton.com/">Jon Leighton</a>. Both Jons were brilliant to work with and we hope to run into them again on future projects. More recently, the marketing/main site of Orchestrate was developed by Ryan Carson and his team at <a href="http://www.carsonified.com/">Carsonified</a>.</p>
<p>Andy has brought together some of the best developers and designers in the world for this project, and it is so wonderful that at Mocra we can now proudly point to Orchestrate as one of its growing number of world-class client projects.</p>
<p>Here&#8217;s hoping for a TechCrunch write up&#8230; ! (<strong>Yay it came true!</strong>)</p>
<h3 id="polish_your_rails_project_with_mocra">Polish your Rails project with Mocra</h3>
<p>I want to help you, your business, your boss and your project reach delightful levels of wickedly awesomeness. I&#8217;m so proud of the small team of ace Rails developers here at Mocra and what I know we can do for you. Orchestrate is delicious proof of pudding.</p>
<p>Send an email to <a href="mailto:rails@mocra.com">rails@mocra.com</a> about your current/future projects. Its free to ask for help and I&#8217;ll even throw in the answers for free. Dare us to be more awesome!</p>
<p>While you wait for a reply perhaps learn more about <a href="http://mocra.com/how-we-do-it/">How we do it</a>?</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/16/making-a-pretty-firefox-beta-application-icon/' rel='bookmark' title='Permanent Link: Making a pretty Firefox Beta application icon'>Making a pretty Firefox Beta application icon</a> <small> Here&#8217;s the problem: I install OS X Firefox 3.6b2...</small></li><li><a href='http://drnicwilliams.com/2009/06/30/refer-us-a-client-for-fun-and-profit/' rel='bookmark' title='Permanent Link: Refer us a client for fun and profit'>Refer us a client for fun and profit</a> <small>There&#8217;s only so many hours in the day and only...</small></li><li><a href='http://drnicwilliams.com/2007/06/09/smart-people-doing-smart-things-in-netherlands-rubyenrails-2007/' rel='bookmark' title='Permanent Link: Smart people doing smart things in Netherlands &#8211; RubyEnRails 2007'>Smart people doing smart things in Netherlands &#8211; RubyEnRails 2007</a> <small>Summary: click to select Photo by Thijs van der Vossen,Fingertips...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/04/06/easy-scheduling-by-location-tasks-and-people-a-case-study-of-a-client-application-from-mocra/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Closing in on The Dream: &#8220;one-click-to-deploy Rails apps&#8221;</title>
		<link>http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/</link>
		<comments>http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 06:03:30 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=483</guid>
		<description><![CDATA[Got a simple app you want to build? Allocate 5 minutes for initial code generation, slice setup, and initial deployment. All from the command line. In one command. Booya! How long does it take to start a new Rails project? Surely just a moment? rails new_project -m path/to/some/template.rb But your application isn&#8217;t deployed yet. The [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><img alt="" src="http://img.skitch.com/20090330-8wwbeef7ngijh3qmu6g4ksr7ha.png" title="Logged in via twitter oauth" class="alignright" width="191" height="191" /></p>
<p>Got a simple app you want to build? Allocate 5 minutes for initial code generation, slice setup, and initial deployment. All from the command line. In one command. Booya!</p>
<p>How long does it take to start a new Rails project? Surely just a moment? <code>rails new_project -m path/to/some/template.rb</code></p>
<p>But your application isn&#8217;t deployed yet. The DNS isn&#8217;t ready, the remote slice doesn&#8217;t exist or the config for this new application isn&#8217;t setup. Heck, the code hasn&#8217;t even been pushed to a non-existent remote repository yet.</p>
<p>And what if you&#8217;re going to use something like twitter_auth for authentication? You&#8217;ll need to register your application with Twitter at <a href="http://twitter.com/oauth_clients">http://twitter.com/oauth_clients</a>.</p>
<p>All these things could be automated, surely. Surely?</p>
<p>If they were then you&#8217;d have a &#8220;one click&#8221; command. A new Rails app, pushed into production, and ready to rock and roll. Complete with either restful_authentication or twitter-based oauth integration.</p>
<h3 id="what_does_a_8220one_click8221_rails_and_deploy_command_look_like">What does a &#8220;one click&#8221; rails and deploy command look like?</h3>
<pre>cd Sites
rails -m rails-templates/mocra.rb default-twitter-auth-app

1. restful_authentication
2. twitter_auth
Which user authentication system? 2

1. mocra-primary
2. mocra-secondary
3. crazy-pron-sites
Install http://default-twitter-auth-app.mocra.com application on which slice? 3^H1

1. drnic
2. mocra
Which twitter user?  1
</pre>
<p><strong>Then you wait 3 minutes and 53 seconds.</strong></p>
<div style="margin-left: 30px;">
<p><a href="http://img.skitch.com/20090330-m19kq398xd47cefxu5wcxbp1d5.png"><img alt="" src="http://img.skitch.com/20090330-xjk5rhx5sgkbh22tfqxrfib3i6.png" title="1" class="alignleft" width="152" height="150" style="background-color: #FFFBCC; padding: 5px; margin: 2px; "/></a></p>
<p><a href="http://img.skitch.com/20090330-m46w5d9hqqcp87yx75bwr71ku6.png"><img alt="" src="http://img.skitch.com/20090330-m6p457erdaj14c162kth3a8m5p.png" title="2" class="alignleft" width="150" height="150" style="background-color: #FFFBCC; padding: 5px; margin: 2px" /></a></p>
<p><a href="http://img.skitch.com/20090330-83miatnsgiu6mjw66f4jaip314.png"><img alt="" src="http://img.skitch.com/20090330-8wwbeef7ngijh3qmu6g4ksr7ha.png" title="3" class="alignleft" width="150" height="150" style="background-color: #FFFBCC; padding: 5px; margin: 2px" /></a>
</div>
<p>Then you visit <a href="http://default-twitter-auth-app.mocra.com">http://default-twitter-auth-app.mocra.com</a> and it is working. You click the &#8220;Protected&#8221; link and you are redirected to Twitter to click the &#8220;Allow&#8221; link. You return to the app. You are registered with an account and logged in. You see your own face. You rock.</p>
<p>The rest of the article shows you how to test run it yourself, explain the dependencies and how to install them, and how to unit test your own templates to do similarly fancy things. Hopefully its helpful.</p>
<h3 id="waiting_a_minute_is_tutorial_destructive_to_my_precious_slices">WAITING A MINUTE &#8211; is this tutorial destructive to my precious slices?</h3>
<p>It is safe. <strong>IF you have an existing slicehost slice that was created with the latest deprec gem.</strong></p>
<p>Perhaps backup your slice anyway. But it should be safe. </p>
<p>Deprec installs each application in its own folder and the apache settings are in their own file etc. But when deprec installs apache, passenger, etc it <em>may</em> put them in places you aren&#8217;t expecting. It might not. I just can&#8217;t promise anything.</p>
<h3 id="testimonial_that_the_tutorial_works">Testimonial that the tutorial works</h3>
<p>Ryan Bigg offers the following testimonial to encourage you to actually try out the tutorial:</p>
<blockquote><p>&#8220;I have, dear readers, with as little effort as a few keystrokes, an an application base that allows my users to sign up using their twitter credentials. I have my code base here on my machine, and the running application in production over there at <a href="http://ryan.mocra.com">http://ryan.mocra.com</a>&#8221; Ryan Bigg (<a href="http://github.com/radar">radar</a>)</p></blockquote>
<h3 id="required_gems_for_the_template">Required gems for the template</h3>
<p>There are a couple of one-time-only steps to run to install some gems and setup github and slicehost API keys locally.</p>
<pre>gem install highline
gem install deprec
gem install defunkt-github --source http://gems.github.com
gem install booster-slicehost-tools --source=http://gems.github.com
</pre>
<p>To setup the github gem with your API key:</p>
<pre>* login to [http://github.com/](http://github.com/)
* click [account](https://github.com/account)
* click "Global Git Config"
* copy and paste the two lines of config into the terminal to install the config
</pre>
<p>The github gem will now use this configuration automatically.</p>
<p>To setup the slicehost gem with your API key:</p>
<p>slicehost-slice list<br />
   Please enter your API key since you did not provide one: </p>
<p>To get your slicehost API:</p>
<ul>
<li>login to <a href="https://manage.slicehost.com">https://manage.slicehost.com</a></li>
<li>click &#8220;Account&#8221;</li>
<li>click <a href="https://manage.slicehost.com/api/">API Access</a></li>
<li>click &#8220;Enable API Access&#8221;</li>
<li>copy + paste the API Password into the terminal above</li>
</ul>
<h3 id="required_gems_and_steps_for_using_twitter_auth">Required gems and steps for using twitter_auth</h3>
<p>My fork of the twitter gem includes a <code>twitter register_oauth ...</code> command. If John integrates the code, or writes his own, I&#8217;ll drop my fork and rewrite my template to use his gem. Til then use this one.</p>
<pre>gem install drnic-twitter --source=http://gems.github.com
twitter install
twitter add
</pre>
<p>And enter your twitter account details. You can run the last command any number of times to add personal and corporate/product twitter accounts. I am really impressed with the internals of this gem &#8211; it stores your data in a sqlite3 gem and uses ActiveRecord models to retrieve it. Might create a generator for this in newgem. I also liked the use of the <code>main</code> gem for its command definition. Anyway, we&#8217;re off the topic.</p>
<h3 id="cloning_and_running_the_rails_templates">Cloning and running the rails-templates</h3>
<p>Imagine the above steps were &#8220;Buy an Xbox 360. Buy Guitar Hero.&#8221; Now its the final step. It&#8217;s time to rock.</p>
<pre>cd ~/Sites
git clone git://github.com/drnic/rails-templates.git
DOMAIN=yourdomain.com ORGANIZATION="Your Company of Legends" rails -m rails-templates/mocra.rb my_app
</pre>
<p>A few minutes later you can open <a href="http://my-app.yourdomain.com">http://my-app.yourdomain.com</a> in a browser. It will have <a href="http://github.com/technoweenie/restful-authentication/tree/master">restful_authentication</a>  or twitter oauth integration all setup and working (except email settings for restful_authentication).</p>
<p>It makes me very happy watching it work.</p>
<p>If the above command has stalled after printing &#8216;executing  slicehost-slice list&#8217; then you haven&#8217;t set up your slicehost API key. See the instructions above.</p>
<h3 id="dirty_nasty_assumptions">Dirty, nasty assumptions?</h3>
<p>How can you deploy an entire app and have it up and running without some more configuration? Surely&#8230; surely I&#8217;ve made some nasty assumptions and come up with some dirty defaults?</p>
<p>Yes.</p>
<p>Your application url will be <code>my-app-name.mocra.com</code>. The subdomain is a dasherized version of your application&#8217;s folder name. Use <code>DOMAIN=mycompany.com</code> to change the domain.</p>
<p>Your local and remote database is mysql, accessible with user <code>root</code> and no password. I&#8230; look&#8230; you see there was this dog&#8230; and he ate my homework&#8230; it wasn&#8217;t me&#8230; there was an earthquate, a volcano, a flood&#8230; it wasn&#8217;t me!</p>
<p>You are deploying to slicehost. I do. It has command-line applications to manage slices and DNS. Since I&#8217;m deploying to a subdomain of mocra.com I use slicehost to create a CNAME in the DNS.</p>
<p>Your target slice already exists and has been built using the latest <a href="http://deprec.failmode.com/">deprec</a>. The template let&#8217;s you select an existing slicehost slice to use. If you don&#8217;t have one that was built with deprec, perhaps create a new one.</p>
<p>Gems? Plugins? Yes this template installs the ones that I want. That&#8217;s the point of rails templates &#8211; you create your own set of defaults.</p>
<h3 id="what_do_i_do_to_get_my_own_uber_template">What do I do to get my own uber-template?</h3>
<p>Copy + paste the <em>mocra.rb</em> template and hack in your configuration. Fork the github project and push up your file so others can see your awesomeness. </p>
<p>See the section on unit testing templates too.</p>
<h3 id="what8217s_missing">What&#8217;s missing?</h3>
<p>The primary thing that I want that I haven&#8217;t gotten around to writing/fixing/finding a solution is the creation of private, company github projects. That is, instead of public/open-source, personal projects using <code>github create-from-local</code>.</p>
<p>I guess I would want a <code>github create-from-local --private</code> flag to create a private repo instead of a public repo.</p>
<p>Then I&#8217;d want the github gem to know that I live in a world of multiple github accounts: my personal account (<a href="http://github.com/drnic/">drnic</a>) and my company&#8217;s account (<a href="http://github.com/mocra/">mocra</a>). That is, I&#8217;ll want new private company projects to go on the company account.</p>
<p>And then I&#8217;ll want it to add me (drnic) as a collaborator. Or a whole group of people.</p>
<p>Since the github gem currently derives its user + API token information from your global git config (<code>git config --get github.user</code>), instead of a nice external sqlite3 database like the twitter gem, I&#8217;m not sure what the best/correct data structure would be to add multiple user support to the github gem. </p>
<p>Or perhaps the <code>github create-from-local</code> mechanism should be extracted out of the github gem all together into a <code>github-admin</code> gem which would have multiple users, create public/private repos, add collaborators etc. Yeah, that might be better.</p>
<h3 id="want_a_default_application_theme">Want a default application theme?</h3>
<p>The template will attempt to invoke a generator <code>app_layout</code> if it can find it. Watch the <a href="http://railscasts.com/episodes/58-how-to-make-a-generator">railscast on generators</a> for an example of how to create a local generator and he gives an example of creating a default application theme generator. That&#8217;s why all the railscasts applications look the same!</p>
<h3 id="bonus_section_unit_testing_a_rails_template">Bonus section: unit testing a Rails template</h3>
<p>If you look in the rails-templates project you cloned you&#8217;ll see a <em>spec</em> folder. There is a mock <em>template_runner.rb</em> which is used by the <em>spec/mocra/template_spec.rb</em>. This way I can stub out calls to command-line tools like <code>slicehost-slice list</code> and <code>twitter register_oauth</code> and check that the template installs the correct plugins, creates the correct files, etc without actually installing or creating anything.</p>
<p>More importantly its a lot bloody faster to run than the full template.</p>
<p>If you&#8217;re creating Rails templates with interesting logic in them then writing some unit tests for your template might be a helpful idea to save time.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2010/03/15/using-coffeescript-in-rails-and-even-on-heroku/' rel='bookmark' title='Permanent Link: Using CoffeeScript in Rails and even on Heroku'>Using CoffeeScript in Rails and even on Heroku</a> <small>I&#8217;m pretty excited about CoffeeScript as a clean-syntax replacement for...</small></li><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/11/03/first-look-at-rails-3-0-pre/' rel='bookmark' title='Permanent Link: First look at rails 3.0.pre'>First look at rails 3.0.pre</a> <small> This article is out of date in some aspects....</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/03/30/closing-in-on-the-dream-one-click-to-deploy-rails-apps/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Testing outbound emails with Cucumber</title>
		<link>http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/</link>
		<comments>http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 04:59:08 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=474</guid>
		<description><![CDATA[My testimonial for Cucumber still stands even in 2009. In fact I promise to let you know when I don&#8217;t think Cucumber is the bees-knees of integration testing. I love the step-by-step English instructions of user usage scenarios backed by a simple Ruby DSL for describing real actions on your application for each step. For [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/10/07/hash-bang-cucumber/' rel='bookmark' title='Permanent Link: hash bang cucumber'>hash bang cucumber</a> <small>I don&#8217;t know if this is a good idea or...</small></li><li><a href='http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/' rel='bookmark' title='Permanent Link: Cucumber: building a better World (object)'>Cucumber: building a better World (object)</a> <small>How to write helper libraries for your Cucumber step definitions...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://cukes.info"><img alt="" src="http://img.skitch.com/20090326-nihhcfit3a54xgqb9tfcspd827.preview.jpg" title="Cucumber testimonial" class="alignright" width="340" height="216" /></a></p>
<p>My testimonial for <a href="http://cukes.info/">Cucumber</a> still stands even in 2009. In fact I promise to let you know when I don&#8217;t think Cucumber is the bees-knees of integration testing. I love the step-by-step English instructions of user usage scenarios backed by a simple Ruby DSL for describing real actions on your application for each step.</p>
<p>For testing Rails apps, Cucumber defaults to using <a href="http://github.com/brynary/webrat/tree/master">Webrat</a> on top of Rails&#8217; own integration sessions. With Webrat you actually test that your views match to your controller actions. If I click the &#8220;Submit&#8221; button, then it checks that it invokes an available action correctly. Before Cucumber I could appreciate the merit of Webrat alone, but the two tools combined are instant superheroes of my Rails development crime fighting team. That is, like any superhero TV show at least once every 30 minutes you find yourself saying &#8220;Thank you Mr Cucumber and your trusty sidekick Webrat, you&#8217;re my heroes&#8221;. (BTW, <a href="http://twitter.com/agenteo/status/1386578002">I&#8217;m not alone</a> in this analogy)</p>
<h3 id="testing_emails">Testing emails</h3>
<p>But I wanted to test emails. More interestingly, emails containing links back into my application. Like an activation email on sign up.</p>
<p>Specifically, I wanted a cucumber scenario like this:</p>
<pre>Scenario: Signup for new account
  Given I am on the signup form
  When I fill in "Email" with "drnic@mocra.com"
  And I press "Join"
  Then I should see "An activation email has been sent"
  And I should receive an activation email
  When I click the activation email link
  Then I should see "Your account is active"
</pre>
<p>Within this scenario there are 7 steps. Lines 2, 3, 4 and 7 match to steps from the generated <em>webrat_steps.rb</em> file when you install cucumber.</p>
<p>Line 1 also matches to a webrat step definition. But it requires that you define what &#8220;the signup form&#8221; maps to in your routes. So you need to update <em>features/support/paths.rb</em> to specify what &#8220;the signup form&#8221; url is:</p>
<pre>module NavigationHelpers
  def path_to(page_name)
    case page_name
    when /the signup form/
      signup_path
    end
  end
end
</pre>
<p>So, that leaves us with lines 5 and 6.</p>
<h3 id="email_spec_plugin">email-spec plugin</h3>
<p>I&#8217;m happy using the <a href="http://github.com/bmabey/email-spec/tree/master">email-spec</a> gem/plugin from <a href="http://www.benmabey.com/">Ben Mabey</a>, who is also the lead maintainer of the awesome <a href="http://github.com/bmabey/cucumber-tmbundle/tree/master">Cucumber TextMate bundle</a> and did a wonderful presentation on <a href="http://mwrc2009.confreaks.com/14-mar-2009-15-00-bdd-with-cucumber-ben-mabey.html">Outside-In Development with Cucumber</a> at the recent Mountain West RubyConf (lots of <a href="http://mwrc2009.confreaks.com">great videos available</a>)</p>
<p>To install as a plugin:</p>
<pre>script/plugin install git://github.com/bmabey/email-spec.git</pre>
<p>Then add the following line to your *feature/support/env.rb* file:</p>
<pre>require 'email_spec/cucumber'</pre>
<p>Finally, the plugin comes with some bonus cucumber step definitions which wrap around lots of nice helpers:</p>
<pre>script/generate email_spec</pre>
<h3 id="using_email_spec_step_definitions">Using email-spec step definitions</h3>
<p>Let&#8217;s ignore my desired lines 5 and 6 above and use the step definitions that we get with email-spec. We can replace the two lines with the following:</p>
<pre>And I should receive an email
When I open the email
Then I should see "Please activate your new account" in the subject
When I click the first link in the email
</pre>
<p><strong>Update:</strong> The last line didn&#8217;t used to be in email-spec but it now is. I&#8217;ve removed the example from this article.</p>
<p>I did all this for an existing application and every line of the scenario tested positive/green. Yay!</p>
<h3 id="refactoring_four_steps_into_two">Refactoring four steps into two</h3>
<p>For the sake of demonstration, you now might want to refactor these four steps into two steps to keep your scenarios nice and readable. </p>
<p>That is, how can we convert these 4 steps into our original lines 5 and 6?</p>
<p>The quickest way is to copy and paste the lines and slap some quotes around the text:</p>
<pre>Then /^I should receive an activation email$/ do |email|
  Then 'I should receive an email'
  When 'I open the email'
  Then 'I should see "Please activate your new account" in the subject'
end

When /^I click the activation email link$/ do
  When 'I click the first link in the email'
end
</pre>
<p>That&#8217;s right, you can use <code>Given</code>/<code>When</code>/<code>Then</code> as invocation methods as well as step definition methods. If you don&#8217;t pass these methods a do&#8230;end block then they will match/find/invoke a step rather than define a new one. Very cool.</p>
<p>Alternately, you could implement the two steps using the underlying email helper methods provided by the email-spec plugin:</p>
<pre>Then /^I should receive an activation email$/ do
  unread_emails_for(current_email_address).size.should == 1
  open_email(current_email_address)
  current_email.should have_subject(/Please activate your new account/))
end

When /^I click the activation email link$/ do
  click_first_link_in_email
end
</pre>
<p>Your choice.</p>
<h3 id="configuring_current_email_address">Configuring current_email_address</h3>
<p>All the email-spec helper methods assume that the &#8220;I&#8221; in the scenario has an email address. It uses a method <code>current_email_address</code> for this.</p>
<p>You must change the <code>current_email_address</code> method in the <em>email_steps.rb</em> file to pull out email addresses from wherever they might be located within any given scenario.</p>
<p>For example, here is one definition of the method from one of my projects:</p>
<pre>def current_email_address
  @email || (@current_user &#038;&#038; @current_user.email) || "drnic@mocra.com"
end
</pre>
<h3 id="summary">Summary</h3>
<p>With Cucumber and email-spec it is very easy to send and test emails. So my thanks go to Ben Mabey for this plugin.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/12/dead-simple-javascript-unit-testing-in-rails/' rel='bookmark' title='Permanent Link: Dead simple JavaScript Unit Testing in Rails'>Dead simple JavaScript Unit Testing in Rails</a> <small> Formats: Video/Screencast (410 Mb, torrent) | Video only (vimeo)...</small></li><li><a href='http://drnicwilliams.com/2009/10/07/hash-bang-cucumber/' rel='bookmark' title='Permanent Link: hash bang cucumber'>hash bang cucumber</a> <small>I don&#8217;t know if this is a good idea or...</small></li><li><a href='http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/' rel='bookmark' title='Permanent Link: Cucumber: building a better World (object)'>Cucumber: building a better World (object)</a> <small>How to write helper libraries for your Cucumber step definitions...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/03/26/testing-outbound-emails-with-cucumber/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>RailsCamp.au #5 &#8211; book now</title>
		<link>http://drnicwilliams.com/2009/02/22/railscampau-5-book-now/</link>
		<comments>http://drnicwilliams.com/2009/02/22/railscampau-5-book-now/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 03:24:01 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Mocra]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=466</guid>
		<description><![CDATA[Imagine yourself and a posse of like-minded Ruby hackers on a country retreat with zero internet for a weekend of fun. You&#8217;ll laugh, hack, learn, cry (well, you probably won’t cry… but you know… it felt poetic) and most likely play a crap-load of guitar hero. [manifesto] In chronological order, the first RailsCamps in Australia [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2007/07/09/web-directions-south-workshop/' rel='bookmark' title='Permanent Link: I Still Call Australia Home'>I Still Call Australia Home</a> <small>On the 25th of September I&#8217;m doing a one-day workshop...</small></li><li><a href='http://drnicwilliams.com/2007/04/26/introducing-myconfplan/' rel='bookmark' title='Permanent Link: Railsconf &#8211; the sessions I&#8217;ll be attending'>Railsconf &#8211; the sessions I&#8217;ll be attending</a> <small> http://myconfplan.com/conferences/RailsConf2007/users/drnic This is a new site called MyConfPlan, built...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://railscampau.github.com"><img alt="" src="http://railscampau.github.com/images/yield.png" title="Yield" class="alignright" width="247" height="166" /></a></p>
<blockquote><p>Imagine yourself and a posse of like-minded Ruby hackers on a country retreat with zero internet for a weekend of fun. You&#8217;ll laugh, hack, learn, cry (well, you probably won’t cry… but you know… it felt poetic) and most likely play a crap-load of guitar hero. [<a href="http://railscamp08.org/" title="Rails Camps">manifesto</a>]</p></blockquote>
<p>In chronological order, the first RailsCamps in Australia were in the states: New South Wales, Victoria, New South Wales, and South Australia. </p>
<p>This time, between May 15th and 18th, it&#8217;s in Queensland. God&#8217;s Country. The Sunshine State. Home of <a href="http://en.wikipedia.org/wiki/Steve_Irwin">Steve Irwin</a> (deceased), <a href="http://en.wikipedia.org/wiki/Joh_Bjelke-Petersen">Sir Joh Bjelke-Petersen</a> (deceased), <a href="http://en.wikipedia.org/wiki/Greg_Norman">Greg Norman</a> (expat), <a href="http://images.google.com.au/images?hl=en&amp;client=firefox-a&amp;rls=org.mozilla:en-US:official&amp;q=Keith%20Urban%20Nicole%20Kidman&amp;um=1&amp;ie=UTF-8&amp;sa=N&amp;tab=wi">Keith Urban</a> (expat), and <a href="http://images.google.com.au/images?q=Kristy%20Hinze&amp;oe=utf-8&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a&amp;um=1&amp;ie=UTF-8&amp;sa=N&amp;hl=en&amp;tab=wi">Kristy Hinze</a> (marrying ex-Silicon Graphics/ex-Netscape billionaire Jim Clark; expat). So its a pretty famous and popular place to come from.</p>
<p><a href="http://www.flickr.com/photos/lachlanhardy/3045076837/" title="More Mexican (by Lachlan Hardy)"><img title="More Mexican (by Lachlan Hardy)" class="alignright" src="http://farm4.static.flickr.com/3016/3045076837_f1ff415033_m.jpg" alt="More Mexican (by Lachlan Hardy)" width="240" height="160"></a></p>
<p><a href="http://railscampau5.eventwax.com/rails-camp-5/register">Book your tickets now</a> for <a href="http://railscampau.github.com">RailsCamp #5</a>.</p>
<p><span id="more-466"></span></p>
<ul>
<li>Date: May 15-18 2009</li>
<li>Cost: $164</li>
<li>Where: <a href="http://www.koonjewarre.com/index.html">Koonjewarre Retreat Centre</a>, Gold Coast Hinterland, Queensland</li>
<li>Airport: Gold Coast Airport, Coolangatta</li>
<li>Website for bookings: <a href="http://railscampau.github.com/" title="RailsCamp.au 5 - May 15-18th 2008">http://railscampau.github.com/</a>
</ul>
<h3 id="foreigners_and_railscampau">Foreigners and RailsCamp.au</h3>
<p>There is no official foreigners policy. More generally, there aren&#8217;t too many policies on anything for RailsCamps. Its noteworthy that we&#8217;re a country founded 200 years ago on Britain&#8217;s primary export in the 1800s: shoplifters. So we&#8217;ll accept just about anyone. If you can get through Customs and Quarantine into our country, then we&#8217;ll let you come to RailsCamp. </p>
<p>Since RailsCamp.au starts just after RailsConf finishes, it would seem like an idea back-to-back &#8220;working&#8221; holiday. If you arrive early into Brisbane we&#8217;ll find you some office space to hang out in, or we&#8217;ll point you in the direction of some places to go touristing.</p>
<p>RailsCamp tickets sell out faster than RailsConf tickets, so <a href="http://railscampau.github.com/">decide fast</a>.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2007/07/09/web-directions-south-workshop/' rel='bookmark' title='Permanent Link: I Still Call Australia Home'>I Still Call Australia Home</a> <small>On the 25th of September I&#8217;m doing a one-day workshop...</small></li><li><a href='http://drnicwilliams.com/2007/04/26/introducing-myconfplan/' rel='bookmark' title='Permanent Link: Railsconf &#8211; the sessions I&#8217;ll be attending'>Railsconf &#8211; the sessions I&#8217;ll be attending</a> <small> http://myconfplan.com/conferences/RailsConf2007/users/drnic This is a new site called MyConfPlan, built...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2009/02/22/railscampau-5-book-now/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

