2. 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.
16. 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
22. 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
23. 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
25. 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
39. 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
42. 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