Thursday, April 30, 2009

Installing a Rails plugin from GitHub through a firewall and proxy

I was working on a Ruby on Rails project today with Nigel from Able Technology, and we wanted to install a plugin from GitHub.

We had a few problems because of a corporate firewall and an http proxy server. Only port 80, http traffic was allowed.

To do this in OSX the following steps were necessary:

1. Set the htttp_proxy variable in the shell:

export http_proxy=http://our.proxy:our_port

if your proxy requires a username and password the command is:

export http_proxy=http://username:password@your.proxy:your_port

2. Run the import using http instead of the git protocol:

script/plugin install

Monday, April 20, 2009

Converting English dates to Maori with Ruby

In the project I am working on at the moment (my first Rails project) I needed a quick way to convert a date set in English (with the month and day of the week in full) to Māori.

This was a pretty simple function to write, so in plenty of time for Māori Language Week (27 July - 2 August 2009) here is the Ruby function.

It turns this:

Monday 20 April 2009

into this:

Rāhina 20 Paengawhā-whā 2009

Friday, April 17, 2009

Moving from PHP to Ruby (and Rails)

For the last year or so I have been porting a legacy PHP application to the Kohana framework. This is not really a legacy app that needs replacing - the system is still highly functional and meeting the needs of staff who use it.

The main problem has been maintaining the spaghetti code that is common in PHP apps written circa 2003. It's not really that bad, its just that things have moved on, and it would be a nightmare for anyone else to make changes to the system. Actually it is getting to be a nightmare for me, mostly because adding new features requires an increasing number of ugly hacks.

The port has been an on-again, off again. I began using the CodeIgniter framework, but changed to Kohana when they added support for PHP5 and started adding useful features not in the other framework.

One of the main issues though, has been the rate of change in both projects - CodeIgniter has been slow and steady, while there has (possibly) been more innovation in Kohana.

In the case of CodeIgniter, it did not always have what I needed (and they weren't taking patches), while Kohana was changing a lot with each major release.

I am definitely not saying that the approach taken by the writers of these frameworks is wrong. They are both good products. But for me I want to be writing business logic, not worrying about how to get a (not available) feature working, or having to rewrite code to account for internal framework changes. Life's too short...

My frustration with both frameworks has led me to look into Ruby on Rails. The byline on the website pretty much sums up what I wanted to experience in my daily work writing software - "Web development that doesn't hurt".

Alongside this we've also had the guys from AbleTech working here on a couple of projects, and I have been impressed with what they have been able to achieve with the Rails framework.

To get started I am porting another smaller web app to Rails. It is going well, and I'm getting to like the syntax very much.

True to the Rails methodology, I got the basic app running and deployed (via Capistrano) in about 20 minutes. From there it was straight into recoding the logic.

I'll be writing a follow-up post soon about the experience.