You want a simple Ruby web app, quick, right? Rails too complicated for your needs? You still want to use a database, and your website to look presentable?
Me too! So I created this boilerplate, with just enough but not too much added in. Different people have different definitions of that; this is mine.
This includes the following tools:
- Sinatra as the engine
- Bootstrap to make the website not ugly
- ActiveRecord to interact with a database
- Responsive navbar (source) including a search box, drop-down menu and will shrink on smaller screens
- Set the HTML
title
attribute on a per-page basis - Passes all default rubocop cops
- Deployable to Heroku as-is
- Multiple controllers & helpers demonstrated
- Valid, standard-compliant HTML
- To get the database running locally, it's recommended by Heroku, & myself, that you install postgres locally. Remember to change the contents of database.yml in accordance with your dev setup. Other database engines are available, like sqlite.
- Run
bundle install
- Run
rackup
and your app should be running athttp://localhost:9292
- Develop your database by creating migrations (
bundle exec rake db:create_migration NAME=create_table_name
), these will appear inside db/migrate. Fill the file in as appropriate and run (rake db:migrate
) - Read the Heroku docs for more information about deploying such apps to Heroku
- Add more tools if you'd like - such as SASS or a different template engine if you don't like erb.
- Code awesome stuff!
I've linked to many of the sources above but I'd also like to mention...
- The sinatra-bootstrap repo
- This article on deploying a simple Sinatra App with Postgres to Heroku
- This post helped me organize multiple controllers in a way I was happy with
1: This is hosted on Heroku's free tier. This means that if no-one has visited the site in the last 30 minutes, it shuts down, and thus will take a few seconds to load up again. Therefore it's important to remember that this is not indicative of the typical response time of this lightweight app.