DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

Posted on • Updated on

Day 7: #100DaysofCode - Setting up a Sinatra App - Part 3


If you bundle added all of your gems and ran bundle install your gem file will look similar to this:

gem "sinatra", "~> 2.0"

gem "sinatra-activerecord", "~> 2.0"

gem "activerecord", "~> 6.0"

gem "sqlite3", "~> 1.4"

gem "pry", "~> 0.13.1"

gem "require_all", "~> 3.0"
Enter fullscreen mode Exit fullscreen mode


This file should have been auto-generated after running bundle install . It should have all of your gem specs.


"SINATRA_ENV" is the key to Ruby’s ENV hash and defines your deployment environment, configures our database, and requires all the files in our app.

ENV['SINATRA_ENV'] ||= "development"

require 'bundler/setup'

configure :development do
  set :database, {adapter: 'sqlite3', database: "db/database.sqlite3"}

require_all 'app'
Enter fullscreen mode Exit fullscreen mode


class ApplicationController < Sinatra::Base

  set :views, -> {File.join(root, "../views")}

  get '/' do
    erb :index


Enter fullscreen mode Exit fullscreen mode


    <meta charset="UTF-8">
    <div class="container">
      <%= yield %>

Enter fullscreen mode Exit fullscreen mode


Your Rakefile should be requiring your environment and if you want to be able to run pry in your rake console you should have the following in your rake file:

require_relative './config/environment'

require 'sinatra/activerecord/rake'

desc "Starts console"
task :console do
Enter fullscreen mode Exit fullscreen mode

Now you should be able to run shotgun in your terminal and head over to http://localhost:9393/ in your browser and you should see "Hello".

Next step will be to set up our database by using rake. If you want to browse the rake commands run rake -T in your console.

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Just kidding, it's a personal preference. But you can change your theme, font, etc. in your settings.

The more you know. 🌈