I’ve been working with Git for the last few weeks and have decided to move friendly_id over to Github. The svn repository will remain live for at least a month of so after Rails 2.1 is released, since the support for git-hosted plugins is currently only available in Edge Rails.

For now, all development is being committed to Git, and then patched into the svn repository. So, if you’re using the svn repository don’t worry, it will remain current for a while.

I remember first hearing about Git during the Linux/Bitkeeper contoversy, and recall thinking Linus Torvalds was odd for not using CVS or Subversion over Bitkeeper, and then thinking he was certifiably insane for deciding to roll his own version tracking system once Bitkeeper didn’t work out.

Of course, Linus Torvalds is (a) a better programmer than me and (b) smarter than me, so there you go. Git has evolved into a very nice tracking system; for me everything that was slow and annoying in SVN (namely, comparing revisions and branching) is fast and easy using Git. If you haven’t yet taken a look at it, you should.

You can take a peek at the shiny new friendly_id repository here.

If you’d like to see a quick introduction to Git, take a peek at Sebastian Delmont’s presentation below.


GIT Talk (nyc.rb) from Sebastian Delmont on Vimeo.

I got stuck for a few minutes trying to figure out how to write a unit test to check if a value was being set in the flash using flash.now. In Rails’ Test::Unit you can’t just do something like assert_not_nil flash[:notice] because the flash value is discarded at the end of the request, and so the flash is always nil.

The solution is to use Mocha to mock an instance of ActionController::Flash::FlashHash and capture the value being set. Here was my solution:

def test_create_with_empty_email_sets_error_in_flash
  hash = {}
  ActionController::Flash::FlashHash.any_instance.expects(:now).returns(
    hash
  )
  post :create
  assert_not_nil hash[:error]
end

I recently had to set up Ruby 1.8.6 on a server running Debian Etch stable. Debian is famous for its slow release cycle - Debian stable often lags far behind other Linux releases in terms of software package versions, though it provides an amazingly comprehensive set of well-tested packages and great stability, making it a great choice as a server platform.

However the current release, Etch, comes with Ruby 1.8.5, which is a bit old and has some problems running Mongrel. It’s very easy to download and compile Ruby, installing it in /usr/local, but this bypasses Debian’s packaging system. But it’s easy to do better; using Ruby’s package manager to install Ruby and maintaining all the benefits of having your installed software under package management.

Note that you’ll need to be root to run these commands.

Make sure you haven’t installed ruby in your package manager yet.

Or, if you have, uninstall it before proceeding to avoid package conflicts. Read the comments on the post below for more details.

1) Update your /etc/apt/sources.list, to use Debian’s “unstable” source packages:

deb-src ftp://debian.mirrors.tds.net/debian/ unstable main non-free contrib

2) Update your list of available packages:

apt-get update

3) Install Ruby’s build dependencies:

apt-get build-dep ruby1.8

4) Install Debian’s package management development programs:

apt-get install dpkg-dev

5) Download the Ruby source package and build it:

apt-get source -b ruby1.8

This took about 5 minutes on my system with SATA disks and a 2 gig P4. It creates the following packages:

  • irb1.81.8.6.111-4all.deb
  • libdbm-ruby1.81.8.6.111-4i386.deb
  • libgdbm-ruby1.81.8.6.111-4i386.deb
  • libopenssl-ruby1.81.8.6.111-4i386.deb
  • libreadline-ruby1.81.8.6.111-4i386.deb
  • libruby1.81.8.6.111-4i386.deb
  • libruby1.8-dbg1.8.6.111-4i386.deb
  • libtcltk-ruby1.81.8.6.111-4i386.deb
  • rdoc1.81.8.6.111-4all.deb
  • ri1.81.8.6.111-4all.deb
  • ruby1.81.8.6.111-4i386.deb
  • ruby1.8-dev1.8.6.111-4i386.deb
  • ruby1.8-elisp1.8.6.111-4all.deb
  • ruby1.8-examples1.8.6.111-4all.deb

6) Install the packages:

dpkg -i *.deb

You can also just install the ones you think you’ll need; at very least you’ll want ruby1.81.8.6.111-4i386.deb, and the ri, rdoc and irb packages.

7) Bask in the Ruby 1.8.6 goodness:

norman@randomba:$ ruby -v

ruby 1.8.6 (2007-09-24 patchlevel 111) [i486-linux]

Friendly_id is a plugin for Ruby on Rails which allows you to work with human-friendly strings as well as numeric ids for ActiveRecords, so that you can have urls like “/members/joe” rather than “/members/123” or “/members/123-joe”.

This provides your application with better search engine optimization (SEO), better data security, and more human-friendly URL’s.It can optionally keep track of modified ids, so that you can do 301 redirects the current URL’s of updated resources.

Read more in the RDoc, or download it directly from its subversion repository.

EDIT: now available in two flavors: svn and git.

app_config is a small generator for Ruby on Rails that generates an application.yml file in your config director, and an initializer script to load it. You can then use the application.yml file to store API keys, mail server settings, or any other kind of configuration data that your application needs. The code was inspired by Geoffrey Grossenbach’s Ruby on Rails Code Review pdf.

You can get it using svn or git.