Ruby on Rails

Rails is a hugely popular web development framework, implemented in Ruby.

The first version of Rails was released back in 2004. Embodying the idea of “convention over configuration” it grew rapidly, attracting followers who had become weary of repeating the mundane tasks required by other frameworks. Combined with the highly dynamic nature of the Ruby programming language, the Rails conventions made for a very productive development environment. You only need to watch some of the Rails screencasts to see this productivity in action.

After the 1.x release Rails continued to improve and the code base grew. It wasn’t long before some people began to miss the simplicity of the early releases of Rails, or felt that some of the assumptions that Rails made on their behalf didn’t suit their needs (Rails is known to be “opinionated software”). As a direct result, several other similar Ruby web frameworks were born, such as Merb, Ramaze and Mack.

Merb was arguably the most successful, and the most obvious direct competitor to Rails. The Merb project has since merged with Rails – many of Merb’s design decisions are now being ported to Rails and will be released as part of Rails 3.

Rails Resources

There is a plethora of useful documentation, tutorials and blogs for you to read, but these sites stand out as being worthy of note:

  • Railscasts – regular screencasts from Ryan Bates demonstrating how to achieve specific tasks in Rails.
  • Railsbrain – JavaScript enhanced copies of the Rails API (to be viewed online or downloaded to your computer).
  • News from the edge of Rails – Rails moves fast, and Ryan Daigle’s blog is a great way to keep up with the latest developments.

Articles on Ruby on Rails

3 Unix commands for finding performance problems

A user recently reported poor performance on one of our Rails apps. I pulled up New Relic’s performance graphs and checked what was happening around the time that we received the email. Sure enough there was a massive spike over a 10 minute period in the time taken to serve a request.

Read more: Finding the problem with cut, sort and uniq

Testing Rails with Rack::Test

The biggest news in Rails 2.3 is its support for Rack, the WSGI inspired Ruby web server interface. Of all the Rack goodness that has come along lately, the one that has me the most excited is Bryan Helmkamp’s Rack::Test library, of which Bryan said “Basically, I extracted Merb’s request helper code into a small, reusable, framework agnostic library.”

Read more: Using Rack::Test with Rails

Sharing CSS between Rails and PHP

Many web sites are built using a variety of web applications, using different web frameworks. These sub sites share the same branding and ought to re-use the same CSS and images. How do you re-use these files within your Rails application, without the maintenance overhead of copying and pasting the code into each new application?

Find out how to share CSS between applications

Configure the Expires header for Rails under nginx

The images, CSS and JavaScript files served up by your Rails application can usually be cached by the web browser, rather than being downloaded (or checked) every time the browser loads a page on your site. For a properly configured site the net effect is faster page load times and a vastly improved user experience. Rails gives you some help here, but it doesn’t happen automatically – you need to configure your web server to set the HTTP Expires header. This article explains how to configure the expires header for a Rails application running behind the nginx HTTP proxy server.

Continue reading

database.yml should be checked in

It’s generally acknowledged to be good practice to keep your production database.yml file away from your version control system. Why? So that people snooping around your version control system don’t find your database password. There are plenty of examples out there that tell you how to set your production password with Capistrano, but I’m talking about the database.yml file used during development.

Continue reading

Easy git-svn for Rails (or "git-me-up")

I’ve been trying to persuade git-svn to work properly with Rails plugins that are installed via svn:externals. Whilst working out how to do it I stumbled across several great articles, but I couldn’t get any of the solutions presented to work perfectly. Samuel Tesla’s article is especially informative, but for a long time I couldn’t stop git-svn from trying to commit Git metadata back into my Subversion repository…

After a bit of head scratching I got it sorted, and wrapped the process up in a little utility called git-me-up.

git svn made easy…

Monitoring BackgrounDRb with God

God is a very neat piece of software, frequently used by Rails developers to monitor mongrel servers, and restart them if/when they crash or use up too many system resources.

Its use isn’t limited purely to monitoring web servers though; you can monitor pretty much anything you like. Read on to see how to configure it to monitor the Ruby job processing daemon, BackgrounDRb.

Continue reading