bookmark_borderMultiple Rails apps with Quicksilver

The ~/works directory holds all the rails applications on my mac book. Some of these are VinSol projects, current and old. Some are my personal projects and some are open source apps like beast and radiant. There is a contribute app also as per HasManyThrough Josh’s recommendation.


[13:29:11 mjuneja works]$ ls -l | wc -l
 37

There are 37 rails applications right now. This is purely co-incidental and has nothing to do with 37signals. 😉

If I run all these apps on the default 3000 port, I cannot run more than one app at a time. If I run the apps at random ports, my browser history will not be app-sensitive. I am heavily dependent on my browser’s location bar’s autocomplete feature, so choosing random ports for my apps is not an option.

I want to be able to run apps on different but fixed ports. I need to be able to make use of my browser history. Also I need to spend minimum time configuring any new app.

This is what I did

I created a YAML file called rappaport.yml. The name rappaport is a short form for “rails application ports”, the fact that my wife runs a diamond jewelery business is purely co-incidental 😉

The yaml file consists of application names and they port assigned to them, as show in this sample below

lovetastic:
port: 3000
tperks:
port: 3001
mmbx:
port: 3002

Next, I have a ruby script ss (short for start server) in the ~/works directory.
All the rails projects have a softlink to ss from their RAILS_ROOT. To start the web server for a project, I just need to execute ss from the app’s RAILS_ROOT.

The script assumes that the application name in the yaml file is the same as the directory name under which the rails code for the app lives ( convention over configuration! )

#! /usr/local/bin/ruby

require 'yaml'

apps = YAML.load_file('/Users/mjuneja/works/rappaport.yml')
current_app = Dir.pwd.split("/").last
port = apps[current_app]["port"]
`script/server -p "#{port}"`

Everytime I create a new project, I append the app name and port to rappaport.yml. Also I create a softlink to ss from the RAILS_ROOT.

So I have a fixed port and a standard command to start the server for all my apps.

The next part is training the browser to access the application, on the same port each time, with minimum intervention from me.

Here, I make use of another ruby script called browser.rb.

#! /usr/local/bin/ruby

require 'yaml'

apps = YAML.load_file('/Users/mjuneja/works/rappaport.yml')
File.open("dev_bookmarks.html", "w+") do |f|
apps.each_pair { |k,v| f.print "<a href="http://localhost:#{v&#91;" port"&#93;}"=""> #{k}_dev </a> n" }
end

This script takes rappaport.yml as the input and creates a list of links in a file called dev_bookmarks.html as the output.
I need to execute this script everytime I add a new project to rappaport.yml.

This is what dev_bookmarks.html looks like

<a href="http://localhost:3000"> lovetastic_dev </a>
<a href="http://localhost:3001"> tperks_dev </a>
<a href="http://localhost:3002"> mmbx_dev </a>

Now I just need to add the contents of this file to Quicksilver’s index.
I go to Quicksilver’s Preferences and click on Catalog and drop the file dev_bookmarks.html from finder onto Quicksilver and Click “Rescan source”

In the information panel, I select “omit source items” and “Include content: HTML Links” and Rescan source.

I can see that the content panel contains all the links.

Quicksilver Content Pane

I can see the project links in the content meaning that quicksilver has correctly parsed the content. On the attributes panel, I select “Include in Global Catalog”.

To point my browser to a rails application running on localhost, I invoke the quicksilver hotkey and start entering the project name, and quicksilver prompts me the project name, and it already knows the port number too.

Quicksilver launching the app