I’ve been looking for a Rails example app that demonstrates “best practice” development techniques and provides basic features, to be used as a “skeleton” starting point for development of a new project.

I’m primarily interested in finding an app that is written for Rails 2.0, that implements a RESTful architecture, and uses RSpec for specifications/testing. Optimally, it should implement authentication (using restful_authentication) and authorization, provide an interface for users to manage their accounts (or profiles), and provide a rudimentary administrative interface for adding or deleting users. I’ve looked at a number of open source apps (see the post Survey of Rails Example Applications).

There are three open source social network apps for Rails that come close to fulfilling my requirements. I’ll compare them here.

RailsCoders is the example app from the book Practical Rails Social Networking Sites, published by Apress. It’s a full-featured app and it is RESTful. The author chose to implement his own authentication (using RESTful principles) rather than using the restful_authentication plugin. The app was written for Rails 1.2.3, not Rails 2.0, but an upgrade is relatively easy. It has Test::Unit tests but not RSpec specifications/tests. As of April 11, 2008, it is hosted on GitHub at abradburne/railscoders, where the author has begun work on a new version of the app.

The authors Michael Hartl and Aurelius Prochazka built a social network app named RailsSpace for a book of the same name. RailsSpace doesn’t meet my minimal requirements (not Rails 2.0, not RESTful, no RSpec) but Michael Hartl is taking the lead in developing a new social network app named Insoshi, which improves on RailsSpace. It is hosted on GitHub and development has been funded by Y Combinator, a venture capital incubator. Insoshi is a Rails 2.0 app, full-featured and RESTful, uses restful_authentication and RSpec, and thus meets my requirements.

Most of the “Intro to Rails” books show how to develop web apps by writing code and then tests. (The more sophisticated books advise to write the tests and then write the code.) The books give good examples of using the built-in Test::Unit facility. But many experienced Rails developers are now using RSpec. There’s only one book I’ve seen that covers RSpec and that’s Obie Fernandez’s The Rails Way. The book doesn’t really explain why so many developers are moving to RSpec; for that, see an article by Dan North or an article by Dave Astels. They argue that we should be writing specifications, not tests.

There are a few tutorials that introduce RSpec, notably a series on the O’Reilly Network on Behavior Driven Development Using Ruby, with Part 1,Part 2, and Part 3. There are also four Peepcode screencasts, starting with RSpec Basics.

RSpec is in the midst of rapid development and there are enough differences between RSpec version 1.1.0, which introduced new functionality (“user stories’), and earlier versions which are covered in the tutorials, that it is possible to get confused.

UPDATE FOR RAILS 3.0: After seeing what was available, I began developing my own Rails example apps. They’ve become quite popular, judging from the number of Rails developers visiting the GitHub repo. Each is accompanied by a detailed tutorial and an application template that can be used to generate a starter app. You can find them here.

THE ORIGINAL POST (from February 18, 2008):

I’m a firm believer that, as software developers, we always are standing on the toes of those who have gone before us.

So, in that spirit, I’m looking around for Rails example apps that I can use as a starting point for my own.

Many Rails books introduce Rails development through the process of building an example application. The best-documented Rails example apps are the ones in the books. I’ve looked through the books I have at hand. Most of the apps in the books are overly simple (for example, no authentication) or dated (no RESTful architecture).

I looked closely at RailsSpace. The authors Michael Hartl and Aurelius Prochazka fully document the steps to building a typical social networking web site. It is a full-featured app that is more complete than most tutorial applications. Unfortunately, the book was written before RESTful architectures became de rigueur. Only one part of the app is RESTful. Otherwise it might be suitable. UPDATE: Michael Hartl, one of the authors of RailsSpace, is leading development of an open source social network app, named Insoshi, which improves on RailsSpace.

I’ve used the Caboose Sample rails application on other projects, so that’s a potential starting point. The downside? It’s complex and not well documented. (The authors warn, “much of the code is targeted at an intermediate/advanced level”.)

A promising beginning point appears to be the Altered Beast forums application, a newer version of Beast. It’s RESTful. It uses Rails 2.0, rspec, and restful_authentication (with the acts_as_state_machine option). I also liked LovdbyLess, a free open source social network platform. It uses Rails 2.0 but not rspec or restful_authentication.

I’m starting a new project and keeping notes this time! At least that’s my intent.

This despite the lesson I should have learned from the story of Hansel and Gretel about the value of leaving a trail of breadcrumbs.

Blogging is a good way to drop the breadcrumbs. So I set up this blog for the project. Thanks, WordPress. In the past I would have insisted on hosting my own blog on my own servers. And probably have decided to write my own blog software before I wrote the first entry. Well, that’s leaving breadcrumbs for sure, since any blog entries I’ve posted have disappeared into the ether with the inevitable moves to new servers or new hosting services. I’ll let WordPress manage the breadcrumbs this time.

It only took me an hour to find a free blog hosting service, sign up, and post the first two entries. Most of that hour spent trying to figure out why paragraph breaks were ignored when I posted (uh, maybe a browser compatibility issue? because it went away when I switched from Safari to Firefox). Then I installed the ScribeFire extension for Firefox with the idea that maybe it would make it easier for me to post new blog entries. It works or you wouldn’t be reading this.