GitHub Tips: Removing a Remote Branch

April 28, 2008

If you are working on a branch and want to abandon it, what do you do?

It’s easy to remove it from your local repository:

$ git branch -d mybranch # delete branch "mybranch"

And then how do you remove it from a GitHub repository? This works:


$ git push git@github.com:<my_account>/<my_repository>.git :heads/<mybranch>

But there’s an easier way. Scott Chacon suggests:

You can also do (assuming ‘origin’ is the name of your remote):

git push origin :mybranch

Scott Chacon is the author of the Git Internals book from Peepcode.


Interaction Design Resources

April 25, 2008

Most web applications are built by teams of software developers and graphic designers. When software developers build their own sites, they tend to reuse designs they’ve used before or borrow from sites they like. Sometimes they’ll ask a graphic designer to create a few icons or propose a fresh look and feel. For their part, graphic designers tend to want to create the kind of eye-catching design that will win design awards for innovation and creativity. In my experience, most developers and designers are only dimly aware that there is a profession called “Interaction Design.” With any profession, there is a body of knowledge and expertise, and in Interaction Design, it’s all devoted to developing the optimal user experience. Most web applications need interaction design. At a minimum, developers and designers would do well to familiarize themselves with the accumulated body of knowledge from the interaction design field. And, if possible, get an interaction design expert on your team.

I’ve begun collecting favorite sources of information about interaction design:

and I’ll add to this list as I find more.


Open Source Social Network Apps for Rails

April 18, 2008

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.

LovdbyLess is a social network platform from the development firm Less Everything. It is hosted on GitHub at stevenbristol/lovd-by-less. It is RESTful and uses Rails 2.0 but not RSpec or restful_authentication.

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.


Adding RSpec to the RailsCoders Example App

April 17, 2008

Alan Bradburne, the author of RailsCoders, the example app from the book Practical Rails Social Networking Sites, wrote a complete set of tests for the app using the Rails Test::Unit facility.

But I’m using RSpec.

To use RSpec, the first step is to install RSpec and Spec::Rails as plugins.

Then, for me, there was a short detour to install the Textmate bundle for RSpec.

The next step is to run

script/generate rspec

to set up the necessary folders and files.


Upgrading the RailsCoders Example App to Rails 2.0

April 17, 2008

I used Mislav Marohnić’s script to determine if the RailsCoders app is compatible with Rails 2.0:

http://pastie.caboo.se/99900.txt?key=krcevozww61drdeza13e3a

Not bad. A few things needed changing.

From config/environments/development.rb, I removed:

config.breakpoint_server = true

I replaced 23 instances of old-style pagination with use of the will_paginate gem. And I added require ‘will_paginate’ to the config/environment.rb file.

Since I removed the XML-RPC blogging interface, I didn’t have to install Action Web Service, which was dropped from Rails 2.0.

If I hadn’t already removed the code for the mobile interface and uploading photos, I would have had to change five links to use the Rails 2.0 syntax for nested resource named routes. As it was, I had to add :name_prefix => nil to several nested routes in the config/routes.rb file.

Finally, I changed

RAILS_GEM_VERSION = '1.2.3'

to

RAILS_GEM_VERSION = '2.0.2'

in the

config/environment.rb

file.


Simplifying the RailsCoders Example App

April 17, 2008

Alan Bradburne’s RailsCoders, the example app from the book Practical Rails Social Networking Sites, is surprisingly full-featured for a tutorial app. For example, it includes an extensive mobile interface, for access to the app from mobile phones. It also provides a facility for uploading and displaying photos (using attachment_fu).

However, I want a much simpler app to use as the basis for my own example application. It’s useful to see how the author added the additional features. And at some point, for some projects, I might follow his example and add the additional functionality.

But, for now, the mobile interface isn’t useful to me. I don’t like to access web sites from a cellphone (except the iPhone, but that’s a another interface entirely). And I’d like to remove everything that has to do with photos (including tagging of photos). The RailsCoders app uses the file system for storing photos (I prefer to use Amazon S3). And it requires installation of ImageMagick and RMagick which introduce configuration headaches. For my example app, I prefer to leave out any support for photo uploads and add it later as needed.

There’s a side benefit to removing the code for photos and the mobile interface. It removes some of the complicated nested resource named routes, avoiding a clash with the Rails 2.0 routing syntax. And removing the code for the XML-RPC blogging interface eliminates use of Action Web Service, which was dropped from the Rails 2.0 core. I’ve also removed the example code that shows how to use the Google Maps API, Flickr API, and Liquid templates.

In sum, if you have the book, I’ve removed everything described in the second half of Chapter 6, plus Chapters 7 and 10-13.


Installing the RailsCoders Example App

April 17, 2008

Alan Bradburne’s RailsCoders, the example app from the book Practical Rails Social Networking Sites, could be a good beginning point for creating a new Rails app. It is well-documented (in the book), full-featured, and RESTful. I’m going to take a closer look at it.

The RailsCoders source code is available for download as an archive file from the Google Code site. The source code is also available for checkout using Subversion:

svn checkout http://railscoders-net.googlecode.com/svn/trunk/railscoders

It’s also available using Git from the GitHub site at http://github.com/abradburne/railscoders/tree/master which is where I obtained a copy.

Here’s how I got it running.

I created two new MySQL databases:

railscoders_development
railscoders_test

I installed the ar_mailer gem:

sudo gem install ar_mailer

I ran

rake db:migrate

and the RailsCoders app runs successfully.

Before making changes to the RailsCoders example app, I ran

rake db:test:prepare
rake test

to see if it passed all the tests that had been written by the original author.

It fails on

ruby test/unit/photo_test.rb
ruby test/functional/posts_controller_test.rb

and, in the interest of expedience, I commented out the four assertions that were failing.


Getting Started With Git and GitHub Hosting

April 13, 2008

The most popular revision control system for an open source Rails app is Git.

I installed Git using MacPorts with
sudo port install git-core.

After installing Git, I installed the Git bundle for TextMate.

I signed up for Git hosting at GitHub. The process is nearly self-explanatory but I consulted two tutorials, A Tutorial Introduction to Git and Setting up a new Rails app with Git. I discovered I needed to create an ssh public/private key pair on my local machine and add the public key to my GitHub profile before I could push the app to the GitHub repository.

I’ve found two screencasts about using Git wih Rails, from PeepCode and Using Git to Manage and Deploy your Rails Apps from Scott Chacon.

GitHub has their own Git Guides but the best instructions I’ve found for using Git are the Git Guides from the Insoshi open source project.


Subversion or Git: Which Likes Me More?

April 13, 2008

I start any project with a revision control system. On projects of any complexity, I know you absolutely need the ability to make notes about what you’ve changed every time you make an improvement. And you need the ability to roll back to an earlier version when your improvements weren’t improvements. You also get the bonus of off-site backup of your code (assuming you use one of the many no-cost or low-cost repository hosting services).

A few years ago, the only alternative to proprietary revision control systems was the open source CVS. On occasions, it could make grown-ups cry. Subversion (SVN) has become more popular recently and it’s widely used on both open source and closed projects.

If I’m doing a project just for myself or my minions (that is, with a single point of ultimate authority), svn is the best choice. There’s nothing extra needed when you want to use svn on Mac OS X version 10.5 (Leopard); it is included when you install the Developer Tools package. You’ll just need to sign up for a repository hosting service.

For an open source project, there are good reasons to prefer Git, as detailed here by Dr Nic Williams. Git is the distributed revision control system created by Linus Torvalds (the creator of Linux). The most popular choice for a Git repository hosting service is GitHub.