One of the biggest frustrations beginners have with learning Rails is getting their head around all the ‘magic’ that Rails seems to do.
The power of Rails is how quickly you can develop complex apps, this speed comes from all the things Rails does for you in the background. Rails does a lot of complex things in the background that are hidden with abstractions. This is where the perceived ‘magic’ happens.
Sinatra is a small light weight web framework written in Ruby. It allows you to make small web applications quickly. Like Rails, Sinatra is built upon Rack so you can think of it as a bare bones version of Rails. There is no ‘magic’ to speak of as everything is very explicit. This is why learning Sinatra before learning Rails is so beneficial. It reduces the learning curve of learning Rails quite a lot.
Sinatra does a few of the same things that Rails does, but it doesn’t create the file-structure for you. The benefit of doing it yourself (and the main reason we’re learning this at all) is that once you get a feel for how to set up routes and organize your views in Sinatra, the complex file structures and methods in Rails will start to make a whole lot more sense.
There isn’t a whole lot to Sinatra so you can learn it pretty quickly, but as you will see you can build very impressive apps with it.
Look through these now and then use them to test yourself after doing the assignment:
create a file called
frank_says.rb with the following code:
require 'sinatra' get '/frank-says' do 'Put this in your pipe & smoke it!' end
From the command line install the Sinatra gem by typing
gem install sinatra then run the file you created:
ruby frank_says.rb. Then visit the page in your browser at
If you use cloud9 instead of a local environment then you can follow the above instructions but instead run
ruby frank_says.rb -o $IP -p $PORT from the terminal and it will provide you with a link to view your application in the browser. You then simply need to add
/frank-says to the address bar in the browser window that opens running your app.
This section contains helpful links to other content. It isn’t required, so consider it supplemental for if you need to dive deeper into something.