The Sinatra Songbook Project

Shotgun

It’s been a long time since any posts, but there will be more over the summer, including a full project. Just a quick one for today though.

It can be annoying when you are developing an app to keep stopping and restarting the server every time you make changes to the code.

There is a nice little program called Shotgun, written by Ryan Tomako, that will reload the application every time the browser makes a request. It was thought that this was too cumbersome to include in Sinatra by default, but makes sense to use in development.

To install Shotgun, all you need to do is open up a console and type:

sudo gem install shotgun

After you’ve installed Shotgun, it is easy to use. When you come to start the server, instead of typing:

ruby main.rb

… you type this instead:

shotgun main.rb

Shotgun runs on port 9393 (Sinatra uses port 4567 by default), so you need to type http://localhost:9393 into your address bar to see your site.

You can change the port by using the -p option like so:

shotgun -p 4567 main.rb

This should help to speed development up a little and also avoid those moments when nothing seems to work because you forgot to restart the server!