Bruno Miranda's Notebook

Personal Blog about Ruby on Rails, XHTML, CSS, and Design

For those of us who work on various rails apps during the course a week this script is a lifesaver. I always ran into small issues related to having multiple apps running on development mode on on the same domain.

Most of the apps I deal with on the regular basis require authentication. Each site has a different login/password combination that safari is set to pre-fill. The problem with that is safari, or any other browser, has a hard time spotting the difference between http://0.0.0.0:3000 and http://0.0.0.0:3000. Possibly because they are the same address.

Another issue you may possibly encounter is that if you use some some of automatic time tracking tool like RescueTime (which is awesome) it will not be able to tell the difference between apps either (in case you wanted to tag them differently)

/etc/hosts to the rescue

Step one is to edit you /etc/hosts line:

127.0.0.1 localhost

to

127.0.0.1 localhost myblog clientone yasn

What that step gives you is the ability to browse the to the development version of you app running on any port on localhost at http://myblog:3000.

This will allow the browser to record and auto-fill proper passwords and will also allow RescueTime to properly identify the domains.

This is cool but could become tedious, boot app, open browser, type address (you could bookmark it but still).

#!bin/bash to the rescue

I created a file called go that takes 2 params, the first on is the name of the app that matches the name you gave it on /etc/hosts. Both params are optional the domain will default to 0.0.0.0 and port number to 3000.

Go does a couple of things, it boots the server (webrick or mongrel) on the specified port, opens a safari window and browses to the correct URL supplied as the first param.

#!/bin/bash

if [ -n "$1" ]; then
  SITE=$1
else
  SITE=0.0.0.0
fi

if [ -n "$2" ]; then
  PORT=$2
else
  PORT=0
fi

sleep 3 && open /Applications/Safari.app http://$SITE:300$PORT & script/server -p 300$PORT

Save that anywhere you’d like, preferably a folder included in your path make it executable and you are done.

Now from the prompt inside you app you can run go myblog 1 and that will boot the server on port 3001, open safari and browser to http://myblog:3000.

I am sure this can be massively improved upon. If you have an idea or would like to add to the script please let me know.

Comments: 0 (view/add your own) Tags: Rails, shell

While developing rails applications I find myself starting and stopping mongrel a bunch of times. At Todobebé we have 4 different apps to deal with and sometimes I want to start and stop a couple of them in succession.

I put together a couple of quick aliases in my .bash_profile to help me with that process. All I have to do now is browse to app root, and type

ss
that causes the server to start, brings up a browser window with a new tab and browses to http://0.0.0.0:3000.

I have also create ss1 and ss2, you can have as many as you would. Here is how I did it.

alias ss="sleep 3 && open /Applications/Safari.app 
http://0.0.0.0:3000 & script/server -p 3000"

alias ss1="sleep 3 && open /Applications/Safari.app 
http://0.0.0.0:3001 & script/server -p 3001"

alias ss2="sleep 3 && open /Applications/Safari.app 
http://0.0.0.0:3002 & script/server -p 3002"
Comments: 0 (view/add your own) Tags: Rails, shell