bundle exec ruby tinderpizza.rb
- What is
rack
? - We're using
sinatra
bundle init
- What's in the
Gemfile
bundle install
- Blocks must return a string
- Default status code
200
andcontent type text/html
bundle exec ruby tinderpizza.rb
views
folderviews/layout.erb
This is slightly different than the Sinatra Skeleton App so you can compare. I'm using sinatra-activerecord
gem to save me some steps. Note; the rake db:create_migration
task is different from your code. Because I'm using require "sinatra/activerecord/rake"
in the Rakefile
instead of writing tasks by hand.
- Add gems
gem "sinatra-activerecord"
gem "sqlite3"
- don't need postgres for demogem "rake"
- Add
models
directory - Add
models/pizza.rb
class Pizza < ActiveRecord::Base
end
autoload :Pizza, settings.root + '/models/pizza'
- Add
db
directory - Added
Rakefile
for db tasks- and
rake console
(handy!)
- and
- Added migration
rake db:create_migration NAME=create_pizzas
- Added Validations
- Added
db/seeds.rb
sorake db:seed
works - Added footer and nav to layout
- Added static
/about_us
route - Added
controllers/pizza_controller.rb
- Toppings Belong to Pizzas
controlers/topping_controller.rb
views/toppings
models/pizza.rb
-before_create
db/migrate/XXX_add_secret_key_to_pizzas.rb
- RSpec to test Sinatra
- Need to support different databases for testing and development
- Use
RACK_ENV
- Look at the
set :database
line intinderpizza.rb
RACK_ENV=test rake db:create
RACK_ENV=test rake db:migrate
- Use
- Create specs in folders underneath
./spec
folder bundle exec rspec