SlideShare a Scribd company logo
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 - Vadim Evseev

More Related Content

PDF
Beginning Scala with Skinny Framework #jjug_ccc
PDF
Ruby w/o Rails (Олександр Сімонов)
KEY
Sinatra for REST services
PDF
Sinatra and JSONQuery Web Service
PDF
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
PDF
Sinatra Rack And Middleware
PDF
.NET Architects Day - DNAD 2011
PDF
09 - Fábio Akita - Além do rails
Beginning Scala with Skinny Framework #jjug_ccc
Ruby w/o Rails (Олександр Сімонов)
Sinatra for REST services
Sinatra and JSONQuery Web Service
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Sinatra Rack And Middleware
.NET Architects Day - DNAD 2011
09 - Fábio Akita - Além do rails

Similar to Ambiguous Sinatra - Vadim Evseev (20)

KEY
TorqueBox - Ruby Hoedown 2011
PDF
Introduction to Rails - presented by Arman Ortega
KEY
Rapid Prototyping FTW!!!
KEY
Plug it on!... with railties
PDF
Workshop 17: EmberJS parte II
PDF
Using Sinatra to Build REST APIs in Ruby
KEY
Speedy TDD with Rails
PDF
Rails 4.0
KEY
Introduction to Padrino
PPTX
Sinatra
KEY
Socket applications
PDF
Railties
PDF
RoR 101: Session 2
KEY
How to set up and test a Rails 3 Engine
PDF
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
PDF
Padrino - the Godfather of Sinatra
ZIP
Ruby on Rails
PDF
Functional Scala 2022 - scalajs Alexis.pdf
ZIP
Introducing Merb
PDF
Rack
TorqueBox - Ruby Hoedown 2011
Introduction to Rails - presented by Arman Ortega
Rapid Prototyping FTW!!!
Plug it on!... with railties
Workshop 17: EmberJS parte II
Using Sinatra to Build REST APIs in Ruby
Speedy TDD with Rails
Rails 4.0
Introduction to Padrino
Sinatra
Socket applications
Railties
RoR 101: Session 2
How to set up and test a Rails 3 Engine
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Padrino - the Godfather of Sinatra
Ruby on Rails
Functional Scala 2022 - scalajs Alexis.pdf
Introducing Merb
Rack
Ad

More from Ruby Meditation (20)

PDF
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
PDF
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
PDF
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
PDF
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
PDF
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
PDF
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
PDF
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
PDF
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
PDF
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
PDF
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
PDF
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
PDF
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
PDF
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
PDF
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
PDF
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
PDF
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
PDF
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
PDF
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
PDF
Rails App performance at the limit - Bogdan Gusiev
PDF
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Rails App performance at the limit - Bogdan Gusiev
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Ad

Recently uploaded (20)

PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Digital Strategies for Manufacturing Companies
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
medical staffing services at VALiNTRY
PPTX
Introduction to Artificial Intelligence
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Nekopoi APK 2025 free lastest update
PDF
AI in Product Development-omnex systems
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Softaken Excel to vCard Converter Software.pdf
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Choose the Right IT Partner for Your Business in Malaysia
Wondershare Filmora 15 Crack With Activation Key [2025
CHAPTER 2 - PM Management and IT Context
Digital Strategies for Manufacturing Companies
Odoo Companies in India – Driving Business Transformation.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
ManageIQ - Sprint 268 Review - Slide Deck
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
medical staffing services at VALiNTRY
Introduction to Artificial Intelligence
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How to Migrate SBCGlobal Email to Yahoo Easily
Understanding Forklifts - TECH EHS Solution
Nekopoi APK 2025 free lastest update
AI in Product Development-omnex systems
Operating system designcfffgfgggggggvggggggggg
Softaken Excel to vCard Converter Software.pdf

Ambiguous Sinatra - Vadim Evseev