Michael R. Cook Ruby and Golang Developer

Tag: Bootstrap

Up and Going in Roda: Static Ruby Websites

Post Image

Recently I started experimenting with the Roda framework to build web applications but as there are not many tutorials, or blog posts in general, about Roda, I thought I’d share my experiences here. Over the coming weeks I’ll be writing a number of articles on using Roda but rather than having to duplicate lots of setup code I think it’ll be easier to have a base app to work from. So, in the next two articles I’ll be building an extremely simple blog using Roda, Postgres, and the Sequel ORM. For this first part we’ll deliver static content, leaving User accounts and posts for part two.

For those who want to follow along, my system is Mac OSX 10.9, along with the following software versions;

  • Ruby 2.2.2
  • Postgres 9.4
  • Roda 2.2.0
  • Sequel 4.21.0

Your application may not work if you use a different version of Roda than what I specify here, but for the rest, you shouldn’t encounter any issues if your versions are a little older/newer.

Installation of Ruby and Postgres is left as an exercise for the reader.

Installing Roda

This is actually the simplest part of the whole procedure as Roda is just a regular GEM. We are however going to be using Bundler for our gem management so first you’ll want to install that, followed by Roda;

$ gem install bundler
$ gem install roda

Creating a New App

Unfortunately there are currently no site generators in Roda like there is in Ruby on Rails (rails new myapp). This means we’ll have to generate our application directory and file structure by hand. Here’s the outline that we’ll be using for our simple blog;

- myapp/
  - models/
  - public/
  - views/
  - config.ru
  - Gemfile
  - myapp.rb
  - models.rb

Go ahead, create the base app directory;

$ mkdir ~/myapp
$ cd ~/myapp

I always like to use Bundler for the gem management so we’ll need to create a Gemfile in which we’ll specify the basic gems requirements for delivering static content;

# ./Gemfile

source "https://rubygems.org"

gem "roda", "~> 2.1.0"
gem "tilt", "~> 2.0.1"
gem "erubis", "~> 2.7.0"

Remember to run bundle install now, and each time you make a change to this file.

At present we have just three dependencies; the first is Roda itself, but we’re also including tilt and erubis so that we can use ERB templates in all our views.

Like all Ruby web frameworks, Roda is built on top of Rack, so we’re going to need a config.ru so that when we start the server (with rackup), our application will be loaded;

Read more...

About Me

Hi, my name is Michael and this is my personal blog. Here I’ll be posting various coding thoughts and experiments; everything from writing blogs in Ruby, to Go tools and Z80 Assembly. This site is powered by Thunderaxe, a blogging platform I built using the Roda Ruby framework.