Tag Archives: sinatra

Deploy a Framework Friday #1 with Ruby and Sinatra

Alright, just for fun I’m kicking off a new blog series. I’m going to publish a new “Deploy a Framework Friday” each week for about the next, well, bunch of weeks. There are a TON of frameworks that are available on PaaS Technologies.

This first entry I’m going to implement a simple Sinatra app with Ruby. Nothing fancy, simply a hello world and the respective deployment to a Cloud Foundry PaaS.

First, let’s whip out the super complex code (right, this isn’t complex, I just like sarcasm). The hello.rb file I created.

require 'sinatra'

get '/' do
  "Hello World!"

get '/route' do
  "Hello from a route URI!"

Next add a Gemfile & respective Gemfile.lock as such.


source "http://rubygems.org"
gem 'sinatra'


  remote: http://rubygems.org/
    rack (1.4.1)
    rack-protection (1.2.0)
    sinatra (1.3.2)
      rack (~> 1.3, >= 1.3.6)
      rack-protection (~> 1.2)
      tilt (~> 1.3, >= 1.3.3)
    tilt (1.3.3)



Then deploy using the Cloud Foundry VMC.

vmc push

If you’ve forgotten, be sure to target and login first.

vmc target api.ironfoundry.me
vmc login

That does it. Yeah, not a whole lot to get started working on a Sinatra Project. For more information on Sinatra check out the main web presence here http://www.sinatrarb.com/.

For more information on Cloud Foundry or Iron Foundry click on the respective link.

For the code sample, check out the working “paasIt” code repo on Github.

Next week I’ll do a baseline ASP.NET MVC 4 Application and get it deployed.

Your Bus Is NOT Here! But We’re Working On It…

But myself and fellow hacker & Geoloqi Crew put something together to figure out where the bus is. Nothing super fancy, but the idea is solid. We wanted to get a simple mobile application put together that would identify where it is, what the closest bus stop is, and pull up the next arriving bus(es) for that stop. We were throwing in a few other ideas, such as pulling up specific stops based on your favorites or even specific buses at that route based on your preferred routes.

Pat (@patrickarlt) & I (@adron) started out by pulling in the GTFS data from TriMet. I setup a basic import to turn all the stop locations in the GTFS data into a Place within a layer within Geoloqi. Pat setup a URL that could be used to call down the latest X arriving buses. Then we combined forces figuring out how to efficiently get all of the 7000+ bus stops into Geoloqi. That proved a little bit more of an issue than we thought. Not a huge issue, but one that got Kyle (@kyledrake) and Aaron (@aaronpk) Coding some fast batch solutions to get it all into Geoloqi while Pat & I handled the application.

On Sunday we’re lined up to get the application into a MVP (Minimally Viable Product) state. We’re hoping to be able to maybe even use it tomorrow in at least a simple way. From that point forward we’ll hopefully move past the MVP into other functionality! 🙂

Another thing to note, is that with our basic implementation we’re using GTFS data. This is a data format that is standardized and used by many of the agencies around the country. So technically any transit agency, as long as they have a way to return their route arrivals, can be setup to use our application we’re building. Some of the other GTFS data can be retrieved here;

To check out more, hit up Google’s page on GTFS data sources:  http://code.google.com/p/googletransitdatafeed/wiki/PublicFeeds

Day one of the hackathon has been seriously kick ass! I’ve had a blast and heard some great ideas, seen some great code, even working demo results, and seen amazing skills applied all around! At this juncture, I’m exhausted, got a little more to code, and ready for day 2 of hacking!

The Bus Ride Home, Sinatra Singing on OS-X

This is just a quick getting started I walked through to get Sinatra going on OS-X.

sudo gem install sinatra
sudo gem install shotgun
sudo gem install haml
sudo gem install unicorn

After installing these things I created a new folder in a Rubymine Project.

New Empty Project in Rubymine

New Empty Project in Rubymine

I added a Ruby Class named SinatraSingsOsx to the project. I then realized that Rubymine did not detect that I had installed Sinatra, so I did a quick find in Rubymine to find and get it synced/installed so that Rubymine was aware of the gems.

Rubymine IDE

Rubymine IDE

Using the gem quick install in Rubymine I chose the documentation and dependent gems.

Rubymine Gem Quick Install

Rubymine Gem Quick Install

Once those were synced up I added the following Ruby Code to the file I created in the project.

require 'rubygems'
require 'sinatra'

get '/' do
  "Verified: Server is up and running!"

I then right clicked on the ruby file and selected the “Run the sinatra_singing_osx” which starts up the webrick web server and such.

Rubymine Run Page Dialog

Rubymine Run Page Dialog

Then navigate to http://localhost:4567 and you’ll see the results of the code.

Sinatra Web Application Running in Chrome

Sinatra Web Application Running in Chrome

Now that I’ve run the application in Rubymine I wanted to do the same with Shotgun using the same Ruby code. The first thing I needed to do was stop the server running that Rubymine had launched. If you look at the bottom of the IDE you’ll see the window displaying the current server status.

Web Server Executing

Web Server Executing

On the left hand side of this status window click on the large red button. This will stop the service. To verify just scroll to the bottom of this status window and you will see the message “Process finished with exit code 1“.

Now that I had the server cleaned up and stopped, I started a terminal again and navigated to the directory that the *.rb file is in that I want to start (host/run/execute, I’m not really sure what the appropriate word would really be at this point). So once at the appropriate path (machineName:SinatraSingingOSX adron$) I typed:

shotgun -p 4567 sinatra_singing_osx.rb

Once this executes the same server that Rubymine uses, the WEBrick, will startup the application again. I launched the browser to assure this ran as expected and got the same results as if running it through Rubymine. I guess, it all really depends, want to just start building and checking things out or want to build with an IDE like Rubymine. It all really boils down to taste and what you’re working with. I’ve been going back and forth between pure text editor and IDE just to familiarize myself with both avenues of using Rails and coding with Ruby.

After the verification I hit Ctrl + C to stop the web server. This basically works on the msysgit in Windows, on OS-X, or on whatever distro of Linux you have running. The cool thing is, so does Rubymine. I figured if I was going to work toward familiarization of an IDE and using the terminal I’d use commands and IDEs that would work on whatever OS I’m running. It’s all good synergies that way. 🙂

I wanted to keep this entry pretty short. With that in mind I simply logged what I worked on while en route home on the bus one evening. So on the next bus ride I’m going to tackle getting some specific notes with Sinatra, getting this all pushed into Heroku (of course, I’m all about the Cloud, you didn’t think I’d put it up on a shared host did you!) Until then, chow.