Ambiguous Sinatra
Ambiguous Sinatra
The story about difficulties, 

surprises and workarounds using Sinatra for complex projects. 

Story about walking through the mines field 

from the person who started learning Ruby from RoR framework.
Sinatra
Web project
1. Models, ORM, migrations
2. Routes
3. Assets pipeline
4. Forms, helpers
5. Console
6. Code load
7. Security, CSRF
Cost of support
Other
Models
SinatraRails
ActiveRecord models
Jeremy Evans
Models
Sinatra
Sequel
Rails
ActiveRecord models ActiveRecord /
Models
Sinatra
Sequel models
Rails
ActiveRecord models
dependent options dependent options
Sequel::Model.plugin :association_dependencies
plugin :association_dependencies, some_model: :destroy
counter cache
Models
Sinatra
Sequel models
Rails
ActiveRecord models
counter cache
dependent optionsdependent options
counter cache
Models
Sinatra
Sequel models
Rails
ActiveRecord models
counter cache
require 'sequel_postgresql_triggers'
dependent optionsdependent options
counter cache
too much bicycles
ORM
Rails Sinatra
ActiveRecord, Arel
Jeremy Evans
ORM
Rails Sinatra
ActiveRecord, Arel Sequel
ORM
Rails Sinatra
ActiveRecord, Arel Sequel
gem 'sequel_pg', :require=>'sequel'
overwrites the inner loop of the Sequel postgres adapter
row fetching code with a C version
ORM
Rails Sinatra
ActiveRecord, Arel Sequel
gem 'sequel_pg', :require=>'sequel'
plugin pg_json
plugin tree, rcte_tree
Sequel
Migrations
Sinatra
rails db:migrate
Rails
ActiveRecord migrations
Migrations
Rails Sinatra
ActiveRecord migrations Sequel migrations
sequel -m relative/path/to/migrations DBrails db:migrate
namespace :db do
desc 'Run migrations'
task :migrate, [:ver] do |_t, args|
Sequel.extension :migration
require ‘my_app_lib’
    if args[:ver]
puts "Migrating to version
#{args[:ver]}"
Sequel::Migrator.run(DB, 'db/
migrations', target: args[:ver].to_i)
else
puts 'Migrating to latest'
Sequel::Migrator.run(DB, 'db/
migrations')
end
end
end
writing migrations tasks
Routes
Rails Sinatra
by design gem 'sinatra_more'
require 'sinatra_more'
class Application < Sinatra::Base
register SinatraMore::MarkupPlugin
register SinatraMore::RenderPlugin
register SinatraMore::WardenPlugin
register SinatraMore::MailerPlugin
register SinatraMore::RoutingPlugin
end
Routes
Rails Sinatra
by design gem 'sinatra_more'
• code generators for creating new sinatra applications (sinatra_gen)
• generic view and tag helpers (tag, content_tag, input_tag, …)
• asset tag helpers (link_to, image_tag, javascript_include_tag, …)
• full form helpers (form_tag, form_for, field_set_tag, text_field, …)
• full url named route support
• formatting extensions (relative_time_ago, js_escape_html, sanitize_html)
• simple 'mailer' support for sinatra (powered by pony)
• plug and play setup for the excellent Warden authentication system
development has stopped
sinatra_more
Assets pipeline
Rails Sinatra
by design gem 'sinatra-asset-pipeline'
require 'sinatra/asset_pipeline'
class App < Sinatra::Base
register Sinatra::AssetPipeline
… some code …
end
use sprockets-helpers
Forms, helpers
Rails Sinatra
by design, Action View
Jeremy Evans
Forms, helpers
Rails Sinatra
by design, Action View gem 'forme'
Forms, helpers
Rails Sinatra
by design, Action View gem ‘forme’ + SLIM
Forms, helpers
Rails Sinatra
by design, Action View gem ‘forme’ + SLIM
Code load
Rails Sinatra
Autoloading and Reloading Constants Sinatra::Reloader
require "sinatra/reloader"config.cache_classes = false
require "sinatra/base"
require "sinatra/reloader"
class MyApp < Sinatra::Base
configure :development do
register Sinatra::Reloader
also_reload '/path/to/some/file'
dont_reload '/path/to/other/file'
after_reload do
puts 'reloaded'
end
end
... some code ...
end
Code load
Rails Sinatra
Autoloading and Reloading Constants
gem ‘rerun'config.cache_classes = false
Code load
Rails Sinatra
Autoloading and Reloading Constants
gem ‘rerun'config.cache_classes = false
rerun ruby ./app.rb
Code load
Rails Sinatra
Autoloading and Reloading Constants
config.cache_classes = false
require "sinatra/reloader"
gem ‘rerun'
Sinatra Code load
Console
Rails Sinatra
require 'bundler/setup'
Bundler.require(:default)
require File.dirname(__FILE__) + "/lib/app_base.rb"
require File.dirname(__FILE__) + "/lib/app_other.rb"
map "/" do
run AppBase
end
map "/another" do
run AppOther
end
rails c irb -r ./app.rb
config.ru
Console
Rails Sinatra
rails c irb -r ./app.rb
Modular application
Rails Sinatra
by design config.ru
Modular application
Rails Sinatra
module MyApp
  class App < Sinatra::Base
...some code...
use MyApp::Controllers::SomeController
...some code...
end
end
include MyApp
by design config.ru
app.rb
Specs
Rails Sinatra
rspec + turnip + factory_bot … sequel + factory_bot
Specs
Rails Sinatra
rspec + turnip + factory_bot … sequel + factory_bot
NoMethodError: undefined method `save!'
for #<Model:...>
Specs
Rails Sinatra
rspec + turnip + factory_bot … sequel + factory_bot
NoMethodError: undefined method `save!'
for #<Model:...>
a) call FactoryGirl.build(:symbol) to
build a Model instance and after call
that create()
b) add into FactoryGirl model
definition: to_create { |i| i.save }
or
Specs
Rails Sinatra
rspec + turnip + factory_bot … sequel + factory_bot
Security, CSRF
Rails Sinatra
CSRF tokens, security updates gem 'rack_csrf'
require "rack/csrf"
configure do
use Rack::Session::Cookie, secret: "some secret"
use Rack::Csrf, raise: true
end
<form method="post" action="/tweet">
<%= Rack::Csrf.csrf_tag(env) %>
<input type="text" name="message"/>
<input type="submit" value="Submit a tweet!"/>
</form>
Installing CSRF
Cost of support
Rails Sinatra
WE ARE NEED YOUR
MONEY
Rails Sinatra
Cost of support
Jeremy Evans
Rails Sinatra
Cost of support
Ambiguous Sinatra

More Related Content

PDF
Beginning Scala with Skinny Framework #jjug_ccc
PPTX
Sinatra
PDF
Finding Frank - Spotify API.pdf
PPTX
Sinatra
PPT
A Quick Introduction to Sinatra
PPT
A Quick Introduction to Sinatra
PDF
Swing when you're winning - an introduction to Ruby and Sinatra
PDF
Your first sinatra app
Beginning Scala with Skinny Framework #jjug_ccc
Sinatra
Finding Frank - Spotify API.pdf
Sinatra
A Quick Introduction to Sinatra
A Quick Introduction to Sinatra
Swing when you're winning - an introduction to Ruby and Sinatra
Your first sinatra app

Similar to Ambiguous Sinatra (20)

PDF
Web Development with Sinatra
PDF
Sinatra and JSONQuery Web Service
PPTX
Sinatra
PPTX
Ultra fast web development with sinatra
PDF
Using Sinatra to Build REST APIs in Ruby
ODP
Ruby off Rails---rack, sinatra and sequel
KEY
Sinatra for REST services
PPT
Lecture 3 - Comm Lab: Web @ ITP
KEY
Sinatra Intro
PPTX
Rubyonrails 120409061835-phpapp02
PDF
ORUG - Sept 2014 - Lesson When Learning Ruby/Rails
PDF
Web Development using Ruby on Rails
PPT
Ruby On Rails
PDF
Perusing the Rails Source Code
PDF
Sinatra Basics
PDF
Sinatra: прошлое, будущее и настоящее
PDF
Rails - getting started
PDF
FGCU Camp Talk
PDF
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Web Development with Sinatra
Sinatra and JSONQuery Web Service
Sinatra
Ultra fast web development with sinatra
Using Sinatra to Build REST APIs in Ruby
Ruby off Rails---rack, sinatra and sequel
Sinatra for REST services
Lecture 3 - Comm Lab: Web @ ITP
Sinatra Intro
Rubyonrails 120409061835-phpapp02
ORUG - Sept 2014 - Lesson When Learning Ruby/Rails
Web Development using Ruby on Rails
Ruby On Rails
Perusing the Rails Source Code
Sinatra Basics
Sinatra: прошлое, будущее и настоящее
Rails - getting started
FGCU Camp Talk
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Ad

More from Amoniac OÜ (15)

PDF
Dokku your own heroku 21
PPTX
GO in Heterogeneous Language Environments
PDF
Cleaners of Caribbean
PPTX
Ruby JIT Compilation
PDF
Capistrano and SystemD
PPTX
Distributed Cluster in Ruby
PDF
Roda: Putting the Fun Back into Ruby Web Development
PDF
Rubymotion: Overview and Ecosystem
PDF
Rupher
PDF
Different Ways of Integrating React into Rails - Pros and Cons
PDF
Functional Web Apps with WebMachine Framework
PDF
Functional Ruby
PDF
How to Become a Сhef
PDF
Let's Count Bytes! Launching Ruby in 32K of RAM
PDF
Deployment tales
Dokku your own heroku 21
GO in Heterogeneous Language Environments
Cleaners of Caribbean
Ruby JIT Compilation
Capistrano and SystemD
Distributed Cluster in Ruby
Roda: Putting the Fun Back into Ruby Web Development
Rubymotion: Overview and Ecosystem
Rupher
Different Ways of Integrating React into Rails - Pros and Cons
Functional Web Apps with WebMachine Framework
Functional Ruby
How to Become a Сhef
Let's Count Bytes! Launching Ruby in 32K of RAM
Deployment tales
Ad

Recently uploaded (20)

PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Five Habits of High-Impact Board Members
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PPTX
Configure Apache Mutual Authentication
PDF
Architecture types and enterprise applications.pdf
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Two-dimensional Klein-Gordon and Sine-Gordon numerical solutions based on dee...
PPT
Geologic Time for studying geology for geologist
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
A review of recent deep learning applications in wood surface defect identifi...
DOCX
search engine optimization ppt fir known well about this
PPTX
The various Industrial Revolutions .pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
Convolutional neural network based encoder-decoder for efficient real-time ob...
Flame analysis and combustion estimation using large language and vision assi...
A contest of sentiment analysis: k-nearest neighbor versus neural network
Five Habits of High-Impact Board Members
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
OpenACC and Open Hackathons Monthly Highlights July 2025
Configure Apache Mutual Authentication
Architecture types and enterprise applications.pdf
Developing a website for English-speaking practice to English as a foreign la...
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Module 1.ppt Iot fundamentals and Architecture
Two-dimensional Klein-Gordon and Sine-Gordon numerical solutions based on dee...
Geologic Time for studying geology for geologist
Benefits of Physical activity for teenagers.pptx
A review of recent deep learning applications in wood surface defect identifi...
search engine optimization ppt fir known well about this
The various Industrial Revolutions .pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Hindi spoken digit analysis for native and non-native speakers
Final SEM Unit 1 for mit wpu at pune .pptx

Ambiguous Sinatra