<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Adventures In Coding</title>
	
	<link>http://adventuresincoding.com</link>
	<description>Toronto based Ruby on Rails developer Kevin Faustino's technical blog about Ruby on Rails, JavaScript, and Software Development</description>
	<lastBuildDate>Tue, 31 Aug 2010 14:48:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AdventuresInCoding" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="adventuresincoding" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>34 Ruby on Rails 3 resources to get you started</title>
		<link>http://adventuresincoding.com/2010/08/34-ruby-on-rails-3-resources-to-get-you-started/</link>
		<comments>http://adventuresincoding.com/2010/08/34-ruby-on-rails-3-resources-to-get-you-started/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 04:28:02 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=286</guid>
		<description><![CDATA[With the upcoming final release of Ruby on Rails 3 around the corner, get up to speed quickly with the following 34 resources.]]></description>
			<content:encoded><![CDATA[<p>With the <del datetime="2010-08-30T01:26:55+00:00">upcoming</del> final release of Ruby on Rails 3 <del datetime="2010-08-30T01:26:55+00:00">around the corner</del>, get up to speed quickly with the following 34 resources:</p>
<h2>Overviews</h2>
<p><a href="http://guides.rubyonrails.org/3_0_release_notes.html">Rails 3.0 Release Notes</a> - RailsGuides is an invaluable resource for all Ruby on Rails developers. The Rails 3 release notes provides a great overview the api changes and new features added to the framework.</p>
<p><a href="http://railsplugins.org/">RailsPlugins.org</a> &#8211; Find out if your plugins work in Rails 3.</p>
<p><a href="http://adventuresincoding.com/2010/07/having-ruby-on-rails-3-my-way/">Having Ruby on Rails 3 My Way</a> - A tutorial on how to setup Rails 3 with Mongoid, Haml, jQuery, and RSpec with Factory Girl.</p>
<p><a href="http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/">The Rails Module (in Rails 3)</a> - Nick Quaranto outlines some helpful methods in the Rails module.</p>
<p><a href="http://blog.plataformatec.com.br/2010/02/rails-3-i18n-changes/">Rails 3 I18n changes</a> - A quick walkthrough the changes made to I18n.</p>
<p><a href="http://rubyonrails.org/screencasts/rails3">Ruby on Rails 3 Screencast series</a> - The official Ruby on Rails site screencast series by Gregg Pollack.</p>
<h2>ActionController / Rack</h2>
<p><a href="http://blog.plataformatec.com.br/2009/08/embracing-rest-with-mind-body-and-soul/">Embracing REST with mind, body and soul</a> - José Valim introduces RESTful responders within Rails 3 controllers.</p>
<p><a href="http://railscasts.com/episodes/224-controllers-in-rails-3">Railscasts #224 Controllers in Rails 3</a> &#8211; Ryan shows us what&#8217;s new with Rails 3 controllers.</p>
<p><a href="http://www.engineyard.com/blog/2010/render-options-in-rails-3/">Render Options in Rails 3</a> - Yehuda goes through the rendering options available in Rails 3.</p>
<p><a href="http://pivotallabs.com/users/jdean/blog/articles/1370-adding-routes-for-tests-specs-with-rails-3">Adding Routes for tests / specs with Rails 3</a> - Jeff Dean outlines how to verify routes in our specs.</p>
<p><a href="http://jasonseifer.com/2009/04/08/32-rack-resources-to-get-you-started">32 Rack Resources to Get You Started</a> - A great collection of links to get you familiar with rack.</p>
<h2>ActionMailer</h2>
<p><a href="http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3">New ActionMailer API in Rails 3.0</a> - Mikel Lindsaar demonstrates how to use the new ActionMailer.</p>
<p><a href="http://railsdispatch.com/posts/actionmailer">A Whole New ActionMailer</a> - Mikel Lindsaar&#8217;s Rails Dispatch post giving a tour of the ActionMailer features.</p>
<h2>ActiveRecord/ActiveModel</h2>
<p><a href="http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/">ActiveModel: Make Any Ruby Object Feel Like ActiveRecord</a> &#8211; Yehuda writes about the modularity of ActiveModel.</p>
<p><a href="http://railscasts.com/episodes/219-active-model">Railscasts #219 Active Model </a>- See how to include certain ActiveModel modules to tableless models.</p>
<p><a href="http://railsdispatch.com/posts/activerelation">ActiveRelation: ActiveRecord Gets a Facelift </a> - Carl Lerche introduces the new ActiveRecord finder api.</p>
<p><a href="http://m.onkey.org/2010/1/22/active-record-query-interface">Active Record Query Interface</a> - Pratik gives an overview of the changes made to the ActiveRecord query interface since Rails 2.</p>
<h2>Bundler</h2>
<p><a href="http://gembundler.com/">Gembundler.com</a> -The official project site for Bundler that includes extensive documentation.</p>
<p><a href="http://railsdispatch.com/posts/bundler">Library Management Gets an Update in Rails 3</a> - Andre Arko gives an overview about bundler for the Rails Dispatch blog.</p>
<p><a href="http://railscasts.com/episodes/201-bundler">Railscasts #201 Bundler </a>- A Railscasts by Ryan Bates demonstrating how to use bundler with Rails 3.</p>
<p><a href="http://adventuresincoding.com/2010/02/riding-ruby-on-rails-3-bundler/">AdventuresInCoding.com screencast on Bundler</a> &#8211; Our very first screencast from last February.</p>
<h2>Railties</h2>
<p><a href="http://www.igvita.com/2010/08/04/rails-3-internals-railtie-creating-plugins/">Rails 3 Internals: Railtie &amp; Creating Plugins</a> - Ilya Grigorik goes over Railties in Rails 3.</p>
<p><a href="http://adventuresincoding.com/2010/07/jumpstart-your-ruby-on-rails-3-applications-with-rails-template/">rails-templater</a> - A template project which generates a greenfield Rails 3 application.</p>
<p><a href="http://caffeinedd.com/guides/331-making-generators-for-rails-3-with-thor">Making generators for Rails 3 with Thor</a> &#8211; A tutorial showing you how to use the new generators and how to bundle them in a gem.</p>
<h2>Routes</h2>
<p><a href="http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/">The Lowdown on Routes in Rails 3</a> - Rizwan Reza gives us a great summary of all the different ways to create routes in Rails 3.</p>
<p><a href="http://edgeguides.rubyonrails.org/routing.html">Rails Routing from the Outside In</a> - RailsGuide documentation about the new router.</p>
<h2>Plugins</h2>
<p><a href="http://weblog.rubyonrails.org/2010/2/9/plugin-authors-toward-a-better-future">Plugin Authors: Toward a Better Future</a> - Yehuda goes through the changes for making plugins in Rails 3.</p>
<p><a href="http://railsdispatch.com/posts/building-or-updating-a-rails-3-plugin">Customizing Rails Apps with Plugins </a>- José Valim gives an overview of using responders, simple form, devise, and mail form plugins.</p>
<p><a href="http://blog.plataformatec.com.br/2010/08/devise-1-1-is-out-and-ready-to-rock-with-rails-3/">Devise 1.1 is out and ready to rock with Rails 3</a> - Outlines some new feature in Devise 1.1 including being able to authenticate a given url in the router!</p>
<h2>Books</h2>
<p><a href="http://beginningrails.com/">Beginning Rails 3</a> &#8211; Cloves Carneiro Jr and Rida Al Barazi bring us a great beginner Rails 3 book with examples viewable in gists.</p>
<p><a href="http://my.safaribooksonline.com/9780132480345">The Rails 3 Way</a> - The ultimate Ruby on Rails reference by Obie Fernandez.</p>
<p><a href="http://www.manning.com/katz/">Rails 3 In Action </a>- Ryan Bigg and Yehuda Katz deliver a great Rails book which teaches readers Rails by doing BDD with Cucumber and RSpec.</p>
<p><a href="http://www.railsupgradehandbook.com/">Rails 3 Upgrade Handbook</a> - Jeremy McAnally&#8217;s book gives you 120 pages of information about upgrading your Rails 2 application to version 3.</p>
<p><a href="http://railstutorial.org/">Ruby on Rails Tutorial: Learn Rails by Example</a> &#8211; Michael Hartl&#8217;s ebook that teaches Rails step by step.</p>
<p><strong>Update</strong>:  Rails 3.0.0 was released on August 29th, 2010. To get more details, be sure to read the <a href="http://weblog.rubyonrails.org/2010/8/29/rails-3-0-it-s-done">official announcement</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/08/34-ruby-on-rails-3-resources-to-get-you-started/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Prototypal Inheritance in JavaScript Explained</title>
		<link>http://adventuresincoding.com/2010/07/prototypal-inheritance-in-javascript-explained/</link>
		<comments>http://adventuresincoding.com/2010/07/prototypal-inheritance-in-javascript-explained/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 18:57:25 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=255</guid>
		<description><![CDATA[A look at how to do inheritance in JavaScript using prototypal inheritance]]></description>
			<content:encoded><![CDATA[<p>One of the more advanced topics in JavaScript is how to implement inheritance in your code. The reason why inheritance causes so much confusion is because there are so many ways to implement it in JavaScript.</p>
<p>For those who are unfamiliar with inheritance, it allows us to extend a previously existing entity and supplement it by adding methods/properties to create an entirely new entity. It is an amazing way to reuse code!</p>
<p>Here is <a href="http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)">Wikipedia’s</a> definition:</p>
<blockquote><p>“In object-oriented programming(OOP), Inheritance is a way to compartmentalize and reuse code by creating collections of attributes and behaviors called objects which can be based on previously created objects”</p></blockquote>
<p>There are a variety of JavaScript frameworks that provide a means to perform classical inheritance. Some of these include <a href="http://www.prototypejs.org/learn/class-inheritance">Prototype</a>, <a href="http://mootools.net/docs/core/Class/Class">MooTools</a>, and <a href="http://jsclass.jcoglan.com/">ClassJS</a>. This is a great option for a team where most of the developers come from other object-oriented languages. Even though the above implementations are viable solutions, Douglas Crockford suggests the ideal solution is to use the prototypal inheritance, which has objects inheriting from other objects</p>
<h2>Implementation</h2>
<p>In JavaScript everything is an object, there is no concept of a class like other object-oriented programming languages. With prototypal inheritance, we implement inheritance by creating objects which will act as prototypes for other objects.</p>
<p>My favourite implementation comes from Stoyan Stefanov’s book <a href="http://www.amazon.com/Object-Oriented-JavaScript-high-quality-applications-libraries/dp/1847194141/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1280256010&amp;sr=8-1">Object-Oriented JavaScript: Create scalable, reusable high-quality JavaScript applications, and libraries</a>. Here is my slightly modified version of a function which abstracts the creation of a child object:</p>
<pre><code>function object(parent, supplements){
  /*  Create a variable that will store our child object. */
  var child;

  /*  Create an empty function F which will act as an intermediary between
      the parent and the child. F will have no properties of its own.	*/
  function F() {};

  /*  Assign the parent constructor to the prototype of F.
      This will allow the child to copy all the parent’s properties without
      having to set it’s prototype to the parent instance. */
  F.prototype = parent;

  /*  Create a new child object from F. We get a copy of all the parent’s properties.
      Functions/objects are copied by reference. */
  child = new F();

  /*  Define a property uber which points to the parent object. Simulates super
      from other languages. */
  child.uber = parent;

  /*  Add any functions/properties desired for the child object. */
  for(var i in supplements){
    child[i] = supplements[i]
  }

  return child;
};</code></pre>
<h2>Example</h2>
<p>Here is a basic example displaying how the properties are copied and overridden in a parent/child relationship.</p>
<pre><code>var parent = {
  firstName: "William",
  lastName: "Adama",
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
};

var child = object(parent, {
  firstName: "Lee"
});

child.fullName(); // "Lee Adama"
parent.fullName(); // "William Adama"</code></pre>
<p>We can implement another version of fullName() that indicates William is Lee’s father without removing the parent function.</p>
<pre><code>child.fullName = function(){
  return this.uber.fullName() + "'s child " + this.firstName;
};

child.fullName(); // "William Adama's child Lee"
parent.fullName(); // "William Adama"</code></pre>
<p>We can even remove our child’s fullName() function and still have access to out parent’s function because it exists in the child&#8217;s prototype chain.</p>
<pre><code>delete child.fullName
child.fullName(); // "Lee Adama"</code></pre>
<h2>Benefits</h2>
<p>The benefit of using prototypal inheritance is that we are working with the strengths of JavaScript and not trying to imitate features of another language.</p>
<p>Not only does it provide an easy way to do inheritance, but there is a performance boost as well. When a function is defined in an object, they are created by reference, resulting in all child objects pointing to the same function and not creating their own copies. This can also lead to some issues if you are unaware of this. If you do not want to share any objects or functions in your child object, make sure to supplement them. Any functions/objects you create in your child object will take precedence over the parent&#8217;s version.</p>
<h2>Out in the Wild</h2>
<p>In the latest ECMAScript 5 standard, prototypal inheritance became a first class citizen as a new native method <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/create">Object.create(proto [, propertiesObject ])</a> was added. It allows you to create a new object with the specified prototype object and properties. You can also use it today in <a href="http://www.yuiblog.com/blog/2010/01/06/inheritance-patterns-in-yui-3/">YUI 3</a> via the Y.Object(&#8230;) function from YUI core.</p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/07/prototypal-inheritance-in-javascript-explained/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to configure Cucumber and RSpec to work with Mongoid</title>
		<link>http://adventuresincoding.com/2010/07/how-to-configure-cucumber-and-rspec-to-work-with-mongoid/</link>
		<comments>http://adventuresincoding.com/2010/07/how-to-configure-cucumber-and-rspec-to-work-with-mongoid/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 17:05:40 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=235</guid>
		<description><![CDATA[RSpec and Cucumber by default are setup to work with relational databases using ActiveRecord. This has been fine for the most part until so many NoSQL databases have come onto the scene. Let’s focus on getting Cucumber and RSpec working with MongoDB using Mongoid. First you will need to setup your Rails 3 application to [...]]]></description>
			<content:encoded><![CDATA[<p>RSpec and Cucumber by default are setup to work with relational databases using ActiveRecord. This has been fine for the most part until so many NoSQL databases have come onto the scene. Let’s focus on getting Cucumber and RSpec working with MongoDB using Mongoid.</p>
<p>First you will need to setup your Rails 3 application to use <a href="http://adventuresincoding.com/2010/07/having-ruby-on-rails-3-my-way/">Mongoid, Cucumber, RSpec, and Factory Girl</a>. Once you have a project skeleton, you will need to setup RSpec to drop all the MongoDB collections of the project before each spec is run to ensure a clean test harness.</p>
<p>The best command to drop your MongoDB collections comes from Mongoid creator Durran Jordan in Mongoid’s <a href="http://github.com/durran/mongoid/blob/master/spec/spec_helper.rb#L32">code base</a>:</p>
<pre><code>Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&#038;:drop)</code></pre>
<h2>RSpec</h2>
<p>Here is a sample RSpec configuration which will empty your MongoDB db and also use Factory Girl to create your models. Note that <em>config.user_transactional_fixtures</em> is commented out.</p>
<pre><code># spec_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'remarkable/active_model'
require 'remarkable/mongoid'
require 'factory_girl'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
  config.mock_with :rspec

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, comment the following line or assign false
  # instead of true.
  # config.use_transactional_fixtures = true

    config.before :each do
      Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&amp;:drop)
    end

end</code></pre>
<h2>Cucumber</h2>
<p>Cucumber allows defining hooks in any file under the <em>features/support</em> directory. To begin setting up Cucumber, first create a file <em>features/support/hooks.rb</em> that will drop your MongoDB collections before each scenario.</p>
<pre><code># features/support/hooks.rb

Before do |scenario|
    Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&#038;:drop)
end</code></pre>
<p>I also find that using Factory Girl for my Cucumber scenarios makes my life a lot easier. Below is an example <em>features/support/env.rb</em> file which will import all your factories. It will also provide some already defined step definitions by the guys at <a href="http://thoughtbot.com/">thoughtbot</a>. Be sure to read about them in their post <a href="http://robots.thoughtbot.com/post/284805810/gimme-three-steps">gimme three steps</a>.</p>
<pre><code># env.rb

ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')

require 'cucumber/formatter/unicode'
require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/web/tableish'

require 'capybara/rails'
require 'capybara/cucumber'
require 'capybara/session'
require 'cucumber/rails/capybara_javascript_emulation'

Capybara.default_selector = :css

ActionController::Base.allow_rescue = false

require 'factory_girl'
require 'factory_girl/step_definitions'
Dir[File.expand_path(File.join(File.dirname(__FILE__),'..','..',
  'spec','factories','*.rb'))].each {|f| require f}</code></pre>
<p>All the step definitions from <em>factory_girl/step_definition</em>s work except for “create record &amp; set one attribute”:</p>
<pre><code>Given an author exists with an email of "author@example.com"</code></pre>
<p>The reason for this is because in the Factory girl <a href="http://github.com/thoughtbot/factory_girl/blob/master/lib/factory_girl/step_definitions.rb#L41">code</a>, theere is a check that determines if the given model responds to :columns. To get around this, add the following code to a new file <em>features/step_definitions/mongoid_steps.rb</em>:</p>
<pre><code># features/step_definitions/mongoid_steps.rb

Given /^an? (.+) exists with an? (.+) of "([^"]*)"$/ do |model, field, value|
  factory_name = model.gsub(' ', '_')
  Factory factory_name, field => value
end</code></pre>
<p><del datetime="2010-07-28T20:21:14+00:00">The last thing to do is stub out the rake task for <em>db:test:prepare</em>. The Cucumber rake tasks are still dependent on the ActiveRecord test workflow and will attempt to load the db schema into the test db. Create the  file <em>lib/tasks/mongo.rake</em> to get around this:</del></p>
<p><strong>Update:</strong> As of version 2.0.0.beta.14 of mongoid, a stubbed rake task for db:test:clone is included.</p>
<pre><code># lib/tasks/mongo.rake

namespace :db do
  namespace :test do
    task :prepare do
      # Stub out for MongoDB
    end
  end
end</code></pre>
<p>Finally, if you don’t want to do this everytime you setup an application, I’ve updated r<a href="http://github.com/kfaustino/rails-templater">ails-templater</a> to do the above steps automatically.</p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/07/how-to-configure-cucumber-and-rspec-to-work-with-mongoid/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Jumpstart your Ruby on Rails 3 applications with rails-templater</title>
		<link>http://adventuresincoding.com/2010/07/jumpstart-your-ruby-on-rails-3-applications-with-rails-template/</link>
		<comments>http://adventuresincoding.com/2010/07/jumpstart-your-ruby-on-rails-3-applications-with-rails-template/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 03:47:15 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=219</guid>
		<description><![CDATA[Announcing rails-templater, a Ruby on Rails 3 template to help create a dummy application in a single line.]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://adventuresincoding.com/2010/07/having-ruby-on-rails-3-my-way/">Having Ruby on Rails my way</a>, I outlined how to manually setup your Ruby on Rails 3 application to use custom generators for Mongoid, Haml, jQuery, RSpec, and factory_girl.</p>
<p>To simplify things further, I have started a template project called <a href="http://github.com/kfaustino/rails-templater">rails-templater</a>. It is inspired by Mike Gunderloy’s <a href="http://github.com/ffmike/BigOldRailsTemplate">BigOldRailsTemplate</a> project which provides templates for Rails 2.3.x projects. To get started, clone the rails-templater repository to your hard drive:</p>
<pre><code>% git clone http://github.com/kfaustino/rails-templater.git</code></pre>
<p>When you are ready to create a new Rails 3 application, run:</p>
<pre><code>% rails new app_name -JOT -m \
 /path/to/rails-tempater/templater.rb</code></pre>
<p>Optionally you can also use <a href="http://compass-style.org/">Compass</a> as your stylesheet framework and <a href="http://github.com/aslakhellesoy/cucumber">Cucumber</a> for integration testing.</p>
<p>I will be continuously making updates to the project by adding new recipes and template options.</p>
<p>Be sure to check out the project <a href="http://github.com/kfaustino/rails-templater">GitHub page</a>.</p>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/dystopos/459452832/">Railroad in Crestwood</a> by dystopos</small></p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/07/jumpstart-your-ruby-on-rails-3-applications-with-rails-template/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Having Ruby on Rails 3 my way</title>
		<link>http://adventuresincoding.com/2010/07/having-ruby-on-rails-3-my-way/</link>
		<comments>http://adventuresincoding.com/2010/07/having-ruby-on-rails-3-my-way/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 17:08:38 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=183</guid>
		<description><![CDATA[A tutorial on how to use the new Ruby on Rails 3 generator hooks to create your ideal application. This post focuses on setting up a Rails application with Mongoid, Haml, jQuery, RSpec, and factory_girl.]]></description>
			<content:encoded><![CDATA[<p>At RailsConf 2009, David Heinemeier Hansson during his <a href="http://railsconf.blip.tv/file/2081411/">keynote</a> mentioned that one of the central themes behind the Ruby on Rails and Merb merge was to “Have it your way”. Given the fact that Rails 3 is almost at a release candidate, I wanted to share my ideal Ruby on Rails setup.</p>
<p>My ideal application stack consists of Mongoid as my ODM, Haml as my template engine, jQuery as my JavaScript framework, RSpec as my testing framework, and factory_girl as my fixture replacement.</p>
<p>I will outline how to setup each of these individually for your Ruby on Rails 3 application.</p>
<p>To begin, generate a new Rails 3 application with the following command:</p>
<pre><code>% rails new app_name -TOJ</code></pre>
<p>The flags passed into the rails command will remove certain elements from the generation of our application.</p>
<p><div style="padding-left: 30px;">T &#8211; represents Test::Unit</div>
<div style="padding-left: 30px;">O &#8211; represents ActiveRecord</div>
<div style="padding-left: 30px;">J &#8211; represents Prototype</div>
</p>
<h2>Replacing ActiveRecord with Mongoid</h2>
<p><a href="http://mongoid.org/">Mongoid</a> is an Object Document Mapper for <a href="http://www.mongodb.org/">MongoDB</a>. It has a beautiful chaining criteria dsl for queries and is optimized for extremely large datasets.</p>
<p>To add mongoid to your project, add the following to your Gemfile:</p>
<pre><code>gem ‘mongoid’, ‘&gt;= 2.0.0.beta14’
gem ‘bson_ext’, ‘1.0.4’</code></pre>
<p>Mongoid provides a generator to setup your project to create mongoid documents for model generation and setup a sample database connection configuration. To run this generator, first execute <em>bundle install</em> to ensure all missing dependencies are installed. Finally, run the <em>mongoid:config</em> generator:</p>
<pre><code>% rails g mongoid:config</code></pre>
<h2>Replacing ERB with Haml</h2>
<p><a href="http://haml-lang.com/">Haml</a> was one of the primary reasons why I feel in love with working on Ruby on Rails applications. It just makes working with markup a pleasure.</p>
<p>Adding Haml to your project requires only 2 lines in your Gemfile:</p>
<pre><code>gem ‘rails3-generators’
gem ‘haml’</code></pre>
<p>The gem <a href="http://github.com/indirect/rails3-generators">rails3-generators</a> provides a variety of generators for Ruby on Rails 3 applications including factory_girl which we will be using later.</p>
<p>In config/application.rb, add the following to your application configuration:</p>
<pre><code>config.generators do |g|
  g.template_engine :haml
end</code></pre>
<h2>Replacing Prototype with jQuery</h2>
<p>Using <a href="http://jquery.com/">jQuery</a> simplifies dealing with the DOM and provides all the tools necessary to do unobtrusive JavaScript in your web application. According to <a href="http://survey.hamptoncatlin.com">Hampton Catlin’s 2010 ruby survey</a>, 78.8% of all ruby users prefer it over Prototype.</p>
<p>Run the following two commands in the root of your project directory:</p>
<pre><code>curl -L http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js &gt; \
public/javascripts/jquery.js

curl -L http://github.com/rails/jquery-ujs/raw/master/src/rails.js &gt; \
public/javascripts/rails.js</code></pre>
<p>Once you setup a layout file, include the two javascript files and your set.</p>
<h2>Replacing Test::Unit with RSpec</h2>
<p>With the latest beta release of <a href="http://github.com/rspec/rspec-rails">RSpec 2</a>, all generators and rake tasks are now exposed through a Railtie.</p>
<p>To replace Test::Unit as your default test framework, include the <em>rspec-rails</em> gem in both the :development and :test group in your Gemfile:</p>
<pre><code>group :development, :test do
  gem ‘rspec-rails’, ‘&gt;= 2.0.0.beta.19’
end</code></pre>
<p>The next step is to install rspec into the application. The <em>rspec:install</em> generator will create a spec directory and some skeleton files. Run the following in your project root:</p>
<pre><code>% bundle install
% rails g rspec:install</code></pre>
<p>Even though you are including RSpec as a development environment dependency, it is not completely loaded. It is only completely loaded when you invoke rails generate or rake. Read more details about this change at David Chelimsky’s post <a href="http://blog.davidchelimsky.net/2010/07/11/rspec-rails-2-generators-and-rake-tasks-part-ii/">rspec-rails-2 generators and rake tasks &#8211; part II</a>.</p>
<h2>Replacing Fixtures with Factory Girl</h2>
<p>The rails3-generators gem we included earlier also provides some <a href="http://github.com/thoughtbot/factory_girl">factory_girl</a> generators. This allows for the creation of a factory when we use the model generator from Rails.</p>
<p>Add a dependency to the <em>factory_girl_rails</em> to the test environment in your Gemfile:</p>
<pre><code>gem 'factory_girl_rails', :group =&gt; :test</code></pre>
<p>You will also need to manually configure your generators to use factory_girl in config/application.rb. Your generators configuration should now look like the following:</p>
<pre><code>config.generators do |g|
  g.template_engine :haml
  g.fixture_replacement :factory_girl, :dir =&gt; "spec/factories"
end</code></pre>
<p><strong>Update:</strong> If you absolutely love this stack, be sure to check out <a href="http://adventuresincoding.com/2010/07/jumpstart-your-ruby-on-rails-3-applications-with-rails-template/">rails-templater</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/07/having-ruby-on-rails-3-my-way/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>10 TextMate bundles/plugins to boost your Ruby on Rails development productivity</title>
		<link>http://adventuresincoding.com/2010/05/10-textmate-bundlesplugins-to-boost-your-ruby-on-rails-development-productivity/</link>
		<comments>http://adventuresincoding.com/2010/05/10-textmate-bundlesplugins-to-boost-your-ruby-on-rails-development-productivity/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 03:42:23 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=152</guid>
		<description><![CDATA[TextMate is a widely used GUI text editor that many in the Ruby on Rails community use. The editor benefits from a large and active community of users whom develop bundles and plugins that extend TextMate’s functionality to work with a wide variety of languages and libraries. Here are ten of my favourite bundles and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://macromates.com/" target="_blank">TextMate</a> is a widely used GUI text editor that many in the Ruby on Rails community use. The editor benefits from a large and active community of users whom develop bundles and plugins that extend TextMate’s functionality to work with a wide variety of languages and libraries.</p>
<p>Here are ten of my favourite bundles and plugins available to TextMate that will save you time and effort while working with Ruby on Rails:</p>
<p>1. <a href="http://peepcode.com/products/peepopen" target="_blank">PeepOpen</a> &#8211; One of the best features of TextMate is fuzzy search(Command-T) which allows you to find files in your project with just a few characters of the filename. The issue with fuzzy search is that it becomes hard to pinpoint a file when there are many files with the same name in your project. Working in Ruby on Rails, you will face an endless amount repeated filenames in your views such as index.html.erb. Geoffrey Grosenbach from PeepCode, has developed an application PeepOpen that replaces the default fuzzy search with a beautiful fuzzy search that also allows you to pinpoint directories within your search. For a mere $9.00, it is a must own add-on to TextMate.</p>
<p><img class="alignnone" title="PeepOpen" src="http://media.adventuresincoding.com/images/posts/peepopen.png" alt="" width="325" height="283" /></p>
<p>2. <a href="http://github.com/carlosbrando/ruby-on-rails-tmbundle" target="_blank">Ruby on Rails</a> &#8211; Ruby on Rails development just got better with the recent changes made by Carlos Brando to <a href="http://github.com/drnic/ruby-on-rails-tmbundle" target="_blank">Dr. Nic’s bundle</a>. Not only does it include all the snippets and Rails integrations we are all used to, but now we also get a pseudo-intellisense for attributes for each ActiveRecord model in your project. One of my favourite additions to the bundle is the ability to easily create <a href="http://adventuresincoding.com/2010/01/taking-the-helm-of-ruby-with-ruby-version-manager/" target="_self">RVM</a> .rvmrc files for your project.  The best resource for this bundle is PeepCode’s <a href="http://peepcode.com/products/textmate-for-rails-2" target="_blank">TextMate for Rails 2</a> screencast, be sure to check it out.</p>
<p>3. <a href="http://github.com/protocool/AckMate" target="_blank">AckMate</a> &#8211; If you need to find some text fast, AckMate is your answer. By default, you have the power of regular expressions to pinpoint even the most complex pattern of text. AckMate also allows the filtering of files by specifying file extensions and pattern matching if a filename contains certain text.</p>
<p style="text-align: left;"><img class="alignnone" title="AckMate" src="http://media.adventuresincoding.com/images/posts/ackmate.png" alt="" width="408" height="421" /></p>
<p>4. <a href="http://github.com/subtleGradient/javascript-tools.tmbundle" target="_blank">JavaScript Tools</a> &#8211; JavaScript is ingrained in web development regardless of the server technology being utilized. Using the JavaScript Tools bundle you get all of the following:</p>
<ul>
<li>JavaScript Lint to check all your source code for common JavaScript mistakes</li>
<li>A JavaScript beautifier to uniform line breaks and indentation</li>
<li>Packing and minimizer tools to compress your JavaScript documents for production</li>
</ul>
<p>5. <a href="http://github.com/kswedberg/jquery-tmbundle" target="_blank">JavaScript jQuery</a> &#8211; jQuery is the most popular JavaScript library available today. This bundle by jQuery team member Karl Swedberg and Jonathan Chaffer provides a huge amount of snippets to save you some keystrokes when working with jQuery.</p>
<p>6. <a href="http://github.com/jcf/git-tmbundle" target="_blank">Git</a> &#8211; The Git bundle provides access to common Git commands without leaving your editor. Do things like viewing your uncommitted changes, find out who made that bad code change, and commit your changes to the repository.</p>
<p>7 &amp; 8. <a href="http://github.com/dchelimsky/rspec-tmbundle" target="_blank">rSpec</a>/<a href="http://github.com/bmabey/cucumber-tmbundle" target="_blank">Cucumber</a> &#8211; Outside-in Rails development has never been easier with Behavior Driven Development (BDD) tools rSpec and Cucumber. These bundles allow for the running of specs and features from within TextMate and provide an HTML output of the results.</p>
<p>9. <a href="http://github.com/mocoso/code-beautifier.tmbundle" target="_blank">Code Beautifier</a> &#8211;  TextMate does a good job of formatting your code but there is room for improvement. Using the Option-Command-B keyboard combination, the Code Beautifier bundle will clean up any white space and fix indentation in your ruby code. This is one of my most used bundles when I work with TextMate.</p>
<p>10. <a href="http://github.com/grimen/compass_blueprint_tmbundle" target="_blank">Compass + Blueprint</a> &#8211; <a href="http://compass-style.org/" target="_blank">Compass</a> is the amazing Sass framework which cuts down development time by providing mixins and a means for doing unobtrusive CSS. This Compass bundle focuses on snippets for the popular <a href="http://www.blueprintcss.org/" target="_blank">Blueprint CSS framework</a>.</p>
<p>Give these bundles/plugins a try and be sure to let me know of any you think belong on this list.</p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/05/10-textmate-bundlesplugins-to-boost-your-ruby-on-rails-development-productivity/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>How to setup Git to use Diffmerge</title>
		<link>http://adventuresincoding.com/2010/04/how-to-setup-git-to-use-diffmerge/</link>
		<comments>http://adventuresincoding.com/2010/04/how-to-setup-git-to-use-diffmerge/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 22:19:43 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=137</guid>
		<description><![CDATA[Merge conflicts, they are bound to happen sooner or later when you are working in parallel with a team of developers. When Git cannot automatically merge changes, a merge fails and the conflicted file becomes littered with &#60;&#60;&#60;&#60;&#60;&#60;&#60;, =======, and &#62;&#62;&#62;&#62;&#62;&#62;&#62; markers.  To ease the pain of having to performing merges, Git allows using one [...]]]></description>
			<content:encoded><![CDATA[<p>Merge conflicts, they are bound to happen sooner or later when you are working in parallel with a team of developers. When Git cannot automatically merge changes, a merge fails and the conflicted file becomes littered with &lt;&lt;&lt;&lt;&lt;&lt;&lt;, =======, and &gt;&gt;&gt;&gt;&gt;&gt;&gt; markers.  To ease the pain of having to performing merges, Git allows using one of many supported merge tools or you can configure Git to use the tool of your choice instead.</p>
<p>In this post, I am going to show you how to do the latter in Mac OS X using my preferred merge tool, <a href="http://www.sourcegear.com/diffmerge/index.html">Diffmerge</a>.  Diffmerge is a  free graphical file comparison tool by SourceGear available in Mac OS X, Linux, and Windows. It is ideal to perform 3-way merges as it supports 3-way file comparison. During a conflict, you are presented with the version of the branch you are working on, the common file ancestor, and the branch you are merging in.</p>
<h2>Visual Mergetool Configuration</h2>
<p>Running the following commands in your terminal will set Diffmerge as your default visual mergetool:</p>
<pre><code>git config --global merge.tool diffmerge

git config --global mergetool.diffmerge.cmd "diffmerge --merge
--result=\$MERGED \$LOCAL \$BASE \$REMOTE"

git config --global mergetool.diffmerge.trustExitCode true</code></pre>
<p>As of the 3.3 release of Diffmerge, exiting a visual merge will return the correct status to Git. Prior to this release, Diffmerge would always return 0, indicating that the merge was resolved even on aborted merges. When you attempt to close Diffmerge, you will be prompted to choose if the merge is to be aborted or is resolved.</p>
<p>To start a 3-way merge with your visual mergetool, run:</p>
<pre><code>git mergetool</code></pre>
<p>This will perform a visual merge for each file in conflict. You may also provide an optional file parameter, to perform a merge on a specific file.</p>
<h3>Don&#8217;t store backups</h3>
<p>By default, Git will store a backup of the original file with conflict markers after a successful merge. These files will have a .orig extension added to the original filename. When I configure Git, I ensure that these files are not saved. To globally disable backups of the original merge file, run the following:</p>
<pre><code>git config --global mergetool.keepBackup false</code></pre>
<h2>Visual Difftool Configuration</h2>
<p>You may also setup Diffmerge to be your visual Difftool by running the following commands in your terminal:</p>
<pre><code>git config --global diff.tool diffmerge
git config --global difftool.diffmerge.cmd "diffmerge \$LOCAL \$REMOTE"</code></pre>
<p>This will allow you to compare two different versions of files visually. For example:</p>
<pre><code>git difftool master~1 foo.rb</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/04/how-to-setup-git-to-use-diffmerge/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Binged In Action</title>
		<link>http://adventuresincoding.com/2010/03/binged-in-action/</link>
		<comments>http://adventuresincoding.com/2010/03/binged-in-action/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 02:31:26 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=124</guid>
		<description><![CDATA[A tutorial on how to incorporate Binged in your Ruby on Rails application]]></description>
			<content:encoded><![CDATA[<p>In our <a href="http://adventuresincoding.com/2010/03/outsource-your-site-wide-search-with-binged/">last post</a>, we introduced <a href="http://github.com/kfaustino/binged">Binged</a>, a simple api wrapper for the Bing API. To demonstrate how to utilize this gem in your Ruby on Rails projects, view the screencast below:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="615" height="335" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=10337665&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="615" height="335" src="http://vimeo.com/moogaloop.swf?clip_id=10337665&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<h3>More Resources</h3>
<ul>
<li><a href="http://github.com/kfaustino/adventuresincoding-examples/tree/master/binged/">Screencast source code</a></li>
<li><a href="http://github.com/kfaustino/binged">Binged source code</a></li>
<li><a href="http://kfaustino.github.com/binged/">Binged Documentation</a></li>
</ul>
<p>Creative Commons:<a rel="cc:attributionURL" href="http://www.flickr.com/photos/chrisjohnbeckett/"><br />
http://www.flickr.com/photos/chrisjohnbeckett/</a> / <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/">CC BY-NC-ND  2.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/03/binged-in-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outsource your site-wide search with Binged</title>
		<link>http://adventuresincoding.com/2010/03/outsource-your-site-wide-search-with-binged/</link>
		<comments>http://adventuresincoding.com/2010/03/outsource-your-site-wide-search-with-binged/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 00:43:27 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=114</guid>
		<description><![CDATA[Why use Bing for your site? The Bing API does not cost you a single penny to use. It&#8217;s completely free! Bing&#8217;s biggest competitor, Google Site Search on the other hand can cost you from $100 annually to a price point only known by calling a google sales representative. Looking at the their small business [...]]]></description>
			<content:encoded><![CDATA[<h2>Why use Bing for your site?</h2>
<p>The <a href="http://www.bing.com/developers">Bing API</a> does not cost you a single penny to use. It&#8217;s completely free! Bing&#8217;s biggest competitor, <a href="http://www.google.com/sitesearch/">Google Site Search</a> on the other hand can cost you from $100 annually to a price point only known by calling a google sales representative. Looking at the their small business plan, it will cost $250 annually for 1,001 &#8211; 5000 indexed pages. If your site has a lot of pages, you will start feeling very limited. Using the Bing API, you have access to the same results as the Bing search engine and not a small subset. The one limitation to the API is that you can only request the first 1000 results of a query. If your site displays 20 results per page, that is a total of 50 pages of search results.</p>
<p>Bing also provides unlimited bandwidth for queries as long as you make less than 7 queries per second per IP address. In a single day, you can query 518,400 times per server. That is a magnitude of search queries that will satisfy even large web applications. Compare this with the $750 annual google plan that only allows 500,000 queries per year!</p>
<p>Finally,  the another great benefit of using the Bing API is that you can style the results to match the look and feel of your site.</p>
<h3>The Rules</h3>
<p>Based on the <a href="http://www.bing.com/developers/tou.aspx">Bing Web Services API Terms of Use</a>, the following rules must be followed in order to use Bing:</p>
<ul>
<li>It is to only be used for display in your Website or application.</li>
<li>You must display some form of attribution to Bing compliant with the Microsoft branding rules.</li>
<li>Do not filter any results you request.</li>
<li>If you interleave with other sources, you must clearly differentiate those sources.</li>
</ul>
<p>Be sure to read the full Terms of Use to know exactly what you are entitled to.</p>
<h2>Bing in Ruby via Binged</h2>
<p><a href="http://github.com/kfaustino/binged">Binged </a>is a ruby gem I wrote that wraps the Bing API. It allows ruby developers to work with bing using all the common ruby syntax and idioms they know. Binged also has a chainable query syntax to allow easy query construction based on a large set of available filters.</p>
<h3>Installation</h3>
<pre><code>[sudo] gem install binged</code></pre>
<h3>Get Your Bing API key</h3>
<p>To use binged, you will require a Bing API key. Create one at: <a href="http://www.bing.com/developers/createapp.aspx">http://www.bing.com/developers/createapp.aspx</a></p>
<h3>Usage</h3>
<h4>Instantiate a Client</h4>
<pre><code>binged = Binged::Client.new(:api_key =&gt; 'binged')</code></pre>
<p>The client is used to search via different sources and holds a reference to your api key to simplify calls to the API.</p>
<h3>Ruby on Rails configuration</h3>
<p>Binged allows for configuration to be done once using a configure block. To use binged in your Ruby on Rails project, configure it globally in an initializer like this:</p>
<pre><code># config/initializers/binged.rb
Binged.configure do |config|
  config.api_key = 'api_key'
end
</code></pre>
<p>Globally configuring Binged removes the need to provide the client with any credentials or options in your code as they would have already been set. For example, defining a client would be as follows:</p>
<pre><code>binged = Binged::Client.new</code></pre>
<h3>Web Search Example</h3>
<p>The following example demonstrates how to search within a specific site for a keyword and provide a maximum of 30 results:</p>
<pre><code>Binged::Client.new.web('ruby').from_site('adventuresincoding.com').per_page(30).each do |result|
  puts result.title
  puts result.description
  puts result.url
end
</code></pre>
<h3>Conclusion</h3>
<p>For simple site-wide search, Bing is the optimal solution for most web applications. It is free and the usage limits are so  lax, they can almost be thought of as unlimited. Be sure to check out the <a href="http://kfaustino.github.com/binged/">Binged documentation</a> to get a grasp of all the conditions you can specify in your queries. If you find a bug or have a great feature idea, <a href="http://github.com/kfaustino/binged/issues">create an issue</a> over at github.</p>
<h3>Update</h3>
<p>View the <a href="http://adventuresincoding.com/2010/03/binged-in-action/">Binged screencast</a> on how to integrate Binged with your Ruby on Rails application.</p>
<p>Creative Commons:<a rel="cc:attributionURL" href="http://www.flickr.com/photos/chrisjohnbeckett/"><br />
http://www.flickr.com/photos/chrisjohnbeckett/</a> / <a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.0/">CC BY-NC-ND 2.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/03/outsource-your-site-wide-search-with-binged/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to clean up your ActiveRecord migrations</title>
		<link>http://adventuresincoding.com/2010/02/how-to-clean-up-your-activerecord-migrations/</link>
		<comments>http://adventuresincoding.com/2010/02/how-to-clean-up-your-activerecord-migrations/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 02:59:49 +0000</pubDate>
		<dc:creator>Kevin Faustino</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://adventuresincoding.com/?p=75</guid>
		<description><![CDATA[Migrations in Ruby on Rails allow you to alter your database using a convenient and easy DSL.  When I started using Rails, migrations were a breath of fresh air. Database schema were finally easy. No longer did I have to pass SQL scripts to developers to run against their development DB or make a huge [...]]]></description>
			<content:encoded><![CDATA[<p>Migrations in Ruby on Rails allow you to alter your database using a convenient and easy DSL.  When I started using Rails, migrations were a breath of fresh air. Database schema were finally easy. No longer did I have to pass SQL scripts to developers to run against their development DB or make a huge script to run at deployment. Migrations took care of this. However the problem with migrations is that after a while, a huge amount of migration files build up in your project. Below are detailed steps on how to clean up your migrations to make managing them easier.</p>
<h2>Step 1: Ensure you include db/schema.rb in your SCM</h2>
<p>The file <code>db/schema.rb</code> is the current definition of your database. It is versioned and updated after a migration is run. This file is essential in creating your database once all your older migrations are gone. Remember that <code>db/schema.rb</code> is db agnostic, so any implementation specific db statements in your migrations will not exist in the schema.</p>
<h2>Step 2: Migrate to the latest version</h2>
<p>Notify your team to checkout the latest version of your project and migrate. This will ensure that future migrations will continue to run smoothly on their current development database.</p>
<h2>Step 3: Seed your database with db/seeds.rb</h2>
<p>Go through each of your migrations and ensure that no data is being inserted in any of them. Migrations are only supposed to be used to manipulate the structure of your database, not populate it.  Rails provides a file <code>db/seeds.rb</code> where you can run ruby code and model creation statements to set all the data required by your application to start.</p>
<p>Below is an example of a <code>db/seeds.rb</code> file setting up the users of a system:</p>
<pre><code>User.create [{ :name =&gt; ‘admin’ }, { :name =&gt; ‘foo’ }, { :name =&gt; ‘bar’ }]</code></pre>
<p>You can populate your database with seed data anytime by running <code>rake db:seed</code>. Seeding was added in Ruby on Rails 2.3.4.</p>
<h2>Step 4:  Keep only latest migrations</h2>
<p>Go to <code>db/migrate</code> folder and delete all but your latest migration or move the older migrations to a folder such as <code>db/archieved_migrations</code>. You will want to keep the last migration as a reference if you need to migrate down.</p>
<h2>Step 5: Setting up a fresh environment</h2>
<p>Even though all your migrations are gone except for one, a developer can setup a fresh environment with a development database containing all required data by running one rake task: <code>rake db:setup</code>. This task will create the database, load the entire schema from <code>db/schema.rb</code>, and then populate the database based on db/seeds.rb.</p>
<div>Creative Commons:</div>
<div><a rel="cc:attributionURL" href="http://www.flickr.com/photos/kaiton/">http://www.flickr.com/photos/kaiton/</a> / <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA 2.0</a></div>
]]></content:encoded>
			<wfw:commentRss>http://adventuresincoding.com/2010/02/how-to-clean-up-your-activerecord-migrations/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
