Archive for January, 2009

Ruby 1.9.1 & Friends

Saturday, January 31st, 2009

I have made a followup postto this which contains more up-to-date information. This post is left here as an example of the state of Ruby 1.9 in January-July 2009.

Last updated: July 11th, 2009

For changes between Ruby 1.8 and Ruby 1.9, look here

So this morning I sat down to give Ruby 1.9.1 a shot with my goal being to get at least the very, very basic Rails application running on it. I’ve run this guide on Mac OS X. Your mileage may vary.

Ruby 1.9.1

Download it from the ruby-lang.org website, install it using autoconf && ./configure –with-readline-dir=/usr/local –program-suffix=1.9 && make && sudo make install and everything should be peachy. I’ve gone about installing Ruby 1.9.1 alongside my current installation of Ruby. If you wish to go the “whole hog” (and I don’t recommend that you do, unless you know how to revert it) don’t run the configure command with the –program-suffix option specified.

Rubygems

Since Ruby 1.9.1 comes with Rubygems now, and this has been confirmed to Just Work ™. The command used was gem1.9.

Rails

gem1.9 install rails rack sqlite3-ruby works too, which is nice to see. The versions of the things installed were:

  • Rails: 2.3.2
  • Rack: 1.0.0
  • Sqlite3 Ruby: 1.2.4

You need the rack gem for running your Rails app and of course the sqlite3-ruby gem because, by default, Rails applications use sqlite3.

The Rails App

We’ll generate a Rails application by typing rails onepointnine and we’ll head into this directory.

Because I’ve installed 1.9.1 alongside 1.8, the version that Rails will try to use by default is 1.8. To fix this, we’ll be running our commands with a ruby1.9 prefix.

We launch our server by ruby1.9 script/server and then go to http://localhost:3000. Welcome aboard! Clicking on “About your application’s environment” should give you something like this. If you don’t see Ruby 1.9.1, you’re using the wrong version of Ruby. Ensure that you launched the server with ruby 1.9 script/server

In another tab, we run ruby1.9 script/generate scaffold blog title:string text:text to get our scaffold and rake1.9 db:migrate to put some tables in our sqlite3 database. Now go to http://localhost:3000/blogs and play around a bit. Everything at this point should be working.

(more…)

Webrat Woes

Friday, January 30th, 2009

Yesterday I wrote a feature for one of the apps at work that was fairly simple it contained this line:

  clicks_link("I am done")

The page contained a link with the text exactly as “I am done” and in all dimensions of this universe you would expect this to pass without fault. It didn’t.

So when this feature failed I brought Bo over and got him to look at it. We couldn’t figure it out yesterday and it took a few hours this morning to figure out what it was. The site was fairly basic, consisting of a layout that contained:

<%= link_to "Things", thing_path %>
<%= yield %>

And the page itself consisted of a form and ended in the link:

<%= link_to "I am done", do_something_path %>

But the bloody feature failed! So we sanity check’d it, output the response’s body and definitely saw the a tag in there. It was there! So we further checked it and tried the URL from the layout and that worked! Major WTF moment there. It took us an hour or so of further WTF before Bo said “Humour me” and gave the layout valid HTML, you know, something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
  <%= link_to "Things", things_path %>
  <%= yield %>
</body>
</html>

And the feature passed! So remember kids, do not be lazy! If you’re testing with webrat remember to always have a valid HTML layout on your site!

Lazy Man’s ri

Saturday, January 24th, 2009

I’ve been working on a gem for the past week called lookup. This lets you type “lookup ActiveRecord::Base” and so on into your terminal and it will open up the relevant documentation.

Testimonials

“It’s fuckin’ handy!” – Bodaniel Jeanes “Going to have to use this for sure!” – rsl “What am I waiting for?” – you

Get it now!

How Dare I!

Tuesday, January 20th, 2009

I left not-so-sunny South Australia without writing anything on my blog saying when I was going! Sorry to all my loyal readers who check at least 50 times daily to see if I have updated. It has been a long time my good friends but I am finally in sunny Queensland and today was my first day back at Mocra which was fantastic!

If any of you wish to come up and visit me, feel free. I do recommend however you fly up because the drive is not only costly, but very freakin’ long (2000km) and very freakin’ boring.

<b>Highlights of the trip</b>

  1. A sign that spanned about 30m on poles about double the thickness of my legs bent backwards with no marks on it whatsoever. It looked. as though the wind had done it.

  2. Parkes Radio Telescope. Biggest. Dish. Ever.

  3. The ever decreasing distance to Brisbane.

  4. Visiting half the states and territories of Australia.

  5. Doing presentation of rboard at Brisbane Ruby Users Group!

<b>Lowlights</b>

  1. “Continue straight for 164km” or “At the roundabout take the second exit”, in 111km. There’s a long time between towns out there.

  2. Losing my mind somewhere between Goondiwindi and Brisbane. Lost concentration and the mind went on a tangent, something about floating continents (think warships, but continents) and people with telekenesis. My imagination is weird and wonderful.