The advent of Rails 1.2 has seen the introduction of the Representational State Transfer (REST) style of software architecture into the framework, but what is REST all about? I could wax lyrical about my understanding of the concepts, however, people far more knowledgeable than myself have already written some fantastic stuff about Rails and REST, therefore I redirect you to a couple of them that have been particularly helpful to me.

Firstly, I point you to a series of introductory articles entitled ‘REST 101’ by Jeff Cohen on the blog Softies on Rails. Thanks Jeff for your explanation, it worked for me.

Secondly, check out the excellent book RESTful Web Services by Leonard Richardson, Sam Ruby published by O’Reilly. Do not be put off by the ‘web services’ part of the title, because this is more than pertinent to Restful Rails web application design.

Hack away and above all have fun!


On the Worldwide Wonder Web there are numerous mentions of metaprogramming in connection with Ruby. Up until now I’ve kinda glossed over it with a mental Postit to investigate later.

Whilst trying to decide what to blog about today I followed a link that took me to Hal Fulton’s (Author of “The Ruby Way”) page and subsequently on to an article that he had written about metaprogramming. The article is a brief introduction to the subject, illustrating the power of Ruby in this regard. The big “R” has mucho mojo dude, check it out.


At some point you will probably want to create some browser content for your web application. If you use Camping that means using Markaby, the Ruby HTML generator. Markaby is baked into Camping and can be installed as a plugin for Rails, but it can just as easily be incorporated into a standard Ruby script.

Define your page layout in Ruby syntax like so (this example was saved as an ordinary ruby script – mktest.rb):-

#!/usr/bin/env ruby

require ‘rubygems’
require ‘markaby’

mab = Markaby::Builder.new
mab.html do
head { title “Things to do” }
body do
h1 “Stuff I need to remember”
ul do
li “Feed the cat”
li “Pay credit card bill”
li “Get a better job”
puts mab.to_s

Then run the code and see the output:-

$:>ruby mktest.rb
<html><head><meta content=”text/html; charset=utf-8″ http-equiv=”Content-Type”/><title>Things to do</title></head><body><h1>Stuff I need to remember</h1><ul><li>Feed the cat</li><li>Pay credit card bill</li><li>Get a better job</li></ul></body></html>

I like it. I like it a lot!


One of the perennial problems that faces a developer when starting to work with new development tools is the set up of the development environment. This process can be one of the most frustrating tasks in IT and can, in some extreme cases, lead the developer to exclaim “Oh WTF!” and simply move on to an easier to manage tool.

In the Apple Mac universe, setting up your development environment yourself is not too problematic, especially if you use Macports and Rubygems. However, utilities like RMagick can be a real pain in the posterior to install, not to mention keeping track of updated versions of things. People, I yearn for simplicity. I do not enjoy struggle for it’s own sake. I make a blood sacrifice to the Ruby Gods and lo, they send me Locomotive.

Locomotive is a self-contained Rails development environment for the Mac and it is magnificently marvellous (Ryan Raaum you are a saint). It contains all the basic ingredients needed to keep a Rails developer happy, integrates with Terminal and Textmate, and has a bundle system that makes installing updates and the infamous RMagick trivial.

If you have a Mac and haven’t tried it yet make tracks to the site.


This is the first post in my Not Obvious To Me (N.O.T.M) section. Here lie examples of my intuitive (or just plain misguided) use of Ruby that have not yielded the results that I expected.

The problem was how to count the occurrences of pairs of newline characters in a given string. I was looking for newline but this case holds good for other repeating characters. Seemed to me that the String.count method should be used. Nice try brother, but how do I break this gently – No! What happens in irb is this:-

irb(main):001:0> str = “Rita, Bob
irb(main):003:0″ and Sue too”
=> “Rita, Bob\n\nand Sue too”
irb(main):004:0> str.count(“\n\n”)
=> 2

As you can see the result is 2, even though I entered a pair of newline characters. What I should have used was the String.scan method like this:-

irb(main):001:0> str = “Rita, Bob
irb(main):003:0″ and Sue too”
=> “Rita, Bob\n\nand Sue too”
irb(main):004:0> str.scan(/\n\n/).size
=> 1

Voila, the answer is 1, just as required. Notice that the result from the scan method is an array, each element containing an occurrence of your search string; consequently the size or length method is invoked to get the number.

This solution was provided by Chad Fowler (not sure whether this is the Ruby-famous Chad) via the ruby-talk-google group. Much obliged.


Task automation is a great way to increase productivity (ask any serious sysadmin) and is overlooked by many computer users because either they don’t know how to do it, or they can’t be bothered to learn yet another language. I’m as guilty as the next guy of continuing to do repetitive actions by hand, shame on me!

Applescript is widely used on the Mac platform to automate tasks, however as a language it leaves a lot to be desired. Enter rb-appscript, a Ruby library “that allows you to control scriptable Mac OS X applications using ordinary Ruby scripts”.

If you need or ought to cut some Applescript code, but you want to get Ruby wid it, just sudo gem install rb-appscript and hack away.


It’s one thing having a lightweight Ruby web application framework like Camping, it’s quite another coming up with useful applications to build with it.

I’m quite a fan of Backpack, which is essentially a personal wiki with some pleasing additional functionality, so I was pleased to find Junebug Wiki, a no-nonsense personal wiki built with Camping.

There is no fat on Junebug, it is minimalist and all the better for that. If you want to add or change functionality then go ahead, you get the source code when you download after all. What does a Junebug wiki look like? Well the Junebug website is a good example.


This old dog needs to retrain. No question, the skillset on my CV is not going to get me where I need and want to be. My personal circumstances have changed, making it imperative that I work from home or very near home which means teleworking is my preferred modus operandi. I have decided that learning Ruby may be the gateway to my goals, but I have a problem.

My CV doesn’t indicate to potential employers that I can hack Ruby because I am self-taught. ‘Self-taught’ in the sense that I have bought books, read articles and collected information from the Internet and completed tutorials. None of this seems to make a jot of difference to employment agencies here in the UK, not to mention that teleworking opportunities seem to be in short supply.

In an attempt to gain some ‘real world’ Ruby experience I have offered my services free of charge in exchange for the opportunity to do some CV friendly Ruby work. I put out a brief message on a couple of Ruby Google Groups asking for help, not really expecting positive feedback. To say that I was pleasantly surprised would be an understatement. Not only did I receive encouragement and support, as luck would have it a kind soul offered to set me some Ruby coding exercises (thank you kind soul!) which I started yesterday.

My faith in human nature somewhat restored, I continue on my quest for that elusive Ruby teleworking gig. If anyone reading this can assist me, please do notĀ  hesitate to get in touch.


For a while now I’ve been a bit fed up with Javascript front-end stuff for web apps. Don’t get me wrong, I have nothing but admiration for the ingenuity of libraries like script.aculo.us, prototype and others, after all they are facilitating a level of browser-based UI richness that is staggering.

Yet something doesn’t sit right with me, AJAX et al and I think I can put my finger on it; it all seems just a bit too complicated. Different browsers requiring special consideration, clever code to allow browsers to do things that they weren’t originally designed to do, it just don’t feeeeel right!

Naturally enough I became a one man hunting party to find that elusive neater front-end and inevitably my path wound up at Adobe’s door. Why Adobe? ‘Tis Flash country brothers and sisters. Wait a second while I don my Nomex suit and prepare for the tongues of flame to roast my nether regions.

OK, I know there are many of you who have issued an IT fatwa on Flash, but listen, put your objections to one side for a moment and consider this; web front-ends built with Flex 2 (Adobe’s Rich Internet Application IDE) play pretty nicely with Rails.

Don’t believe me? Just Google ‘flex + rails’. This ain’t new, even so, I thought that I’d better blog about it just in case you hadn’t considered hooking up Flash via Flex with Rails. The goodness of Flash + the greatness of Rails need I say more?

If you need a consistent cross-browser display platform and you’re not constrained by monetary or ideological issues, put this on your evaluation list.


I’ve been learning French on and off for years. Since leaving school I’ve flirted with it on numerous occasions, however, to date I’m still not fluent.

I’ve been learning Ruby for less timeĀ  and already I feel more at home with it than I do French. It seems that I love the idea of learning French but I love learning Ruby.