Gemfile
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"
Gemfile.lock
This file should have been auto-generated after running bundle install
. It should have all of your gem specs.
environment.rb
"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'
Bundler.require(:default,ENV['SINATRA_ENV'])
configure :development do
set :database, {adapter: 'sqlite3', database: "db/database.sqlite3"}
end
require_all 'app'
application_controller.rb
class ApplicationController < Sinatra::Base
set :views, -> {File.join(root, "../views")}
get '/' do
erb :index
end
end
layout.erb
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<div class="container">
<%= yield %>
</div>
</body>
</html>
Rakefile
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
Pry.start
end
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)