SlideShare a Scribd company logo
Ultra fastwebdevelopmentwithClassyhatrequired.
Ultra fastwebdevelopmentwithfeaturingPedro "Frank" GasparSérgio "Sinatra" Santos
WhatisSinatra?
ThisisSinatra!
A smallwebframeworkfor server-sideapplicationsinrubysinatrarb.com
Setup
WindowsOne-ClickInstaller – go to ruby-lang.orgMac OSX(pre-installed, draw a hatinstead)Linux (Ubuntu)sudoapt-getinstallrubyrubygems
InstallSinatrasudogeminstallsinatraInstalllibssudogeminstallerbdm-coredm-sqlite-adapterdm-migrationsdm-serializerdm-validationsserialport
HelloNew York
hello.rb:require 'sinatra'get '/' do   "New York, New York"end
ruby–rubygemshello.rbgo to http://localhost:4567
Ruby 101
Variableshungry = trueanswer = 42cost =  0.99PI = 3.14name = "Sérgio Santos"fruit = ['apple', 'banana', 'grape']  # fruit[1] -> 'banana'mix = ['door', 37, 15.2, false]names = { 'Sérgio' => 'Santos', 'Pedro' => 'Gaspar' }names['Sérgio']
Conditionsif grade >= 10puts "Yey!"elseputs "humpf"endcase minutes_latewhen 0..5      thenputs "ontime"when 5..15     thenputs "fair"when 15..30  thenputs "late"elseputs "doorclosed"end
Cycleswhilenothungryputs "work"endputs "work" whilenothungry1.upto(10)  {  |n|puts n  }['ruby', 'python', 'php'].each do |language|puts "I cancode " + languageend
Functionsdefgreetings(names)names.each do |first, last|puts "Hello " + first + " " + lastendendnames = { 'Sérgio' => 'Santos', 'Pedro' => 'Gaspar' }greetings(names)
Controllers
get '/moon' do     "Fly me to themoon…"endpost '/destroy-world' do     "Boom"endget '/hello/:name' do    "Hello " + params[:name]end
Sessionsenable :sessionsget '/visit' dosession[:visits] = 0 unlesssession[:visits] session[:visits] += 1     "Youvisitedthispage #{session[:visits]} times."end
Filtersbefore doputsrequest.ipendget '/hello' do "Hi!" endget '/bye' do "Bye!" endafter doputs "Alldone"end
Templates
PublicfolderAll files insidethefolder 'public' are sharedGreat for static files like javascript, css, images…
get '/hello/:name' do    "Hello " + params[:name]end
get '/hello/:name' do     @name = params[:name]erb :helloendtemplate :hello do      "Hello <%= @name %>"end
get '/hello/:name' do     @name = params[:name]erb :helloendviews/hello.erb:Hello <%= @name %>
get '/show' do     @names = ['Sérgio', 'Pedro']erb :showendviews/show.erb:<% if @names.empty? %>    This place is empty.<% else %>   We got:    <% for name in @names %>  <%= name %>  <% end %><% end %>
views/layout.erb:<html>    <head>        <title>My Sinatra App</title>    </head>    <body>         <%= yield %>    </body></html>
Database
require 'sinatra'require 'dm-core'require 'dm-migrations'DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/event.sqlite3")class Person  include DataMapper::Resource  property :id,        Serial  property :name, String  property :email, String  property :date,    Time,   :default => Time.nowendDataMapper.auto_upgrade!
TypesBooleanStringTextFloatIntegerDecimalDateTime, Date, Timehttp://datamapper.org/docs/properties
Operationsperson = Person.create(:name => 'Sérgio‘, :email => 'me@sergiosantos.info')person = Person.newperson.name = 'Sérgio'person.email = 'me@sergiosantos.info'person.saveperson.update(:name => 'Pedro')person.destroyhttp://datamapper.org/docs/create_and_destroy
OperationsPerson.get(5)Person.first( :name => 'Sérgio' )Person.lastPerson.all( :name.like => 'Sérgio' )Person.all( :date.gt => Time.now – 1 * 60 * 60 ) # Last hourhttp://datamapper.org/docs/find
Serializerrequire 'dm-serializer'Person.all.to_xmlPerson.all.to_jsonPerson.all.to_csvPerson.all.to_yaml
Validationsrequire 'dm-validations'class Person    include DataMapper::Resource    property :id,        Serial    property :name, String    property :email, String    property :date,    Time,   :default => Time.nowvalidates_length_of :name, :within => 3..100validates_uniqueness_of :emailendhttp://datamapper.org/docs/validations
Validationsget '/' doerb :indexendpost '/registration' do    @person = Person.create(:name => params['name'], :email => params['email'])    if @person.saved?erb :thanks    elseerb :index    endendviews/index:<p style="color: red;">    <% for error in @person.errors %>        <%= error %><br/>    <% end %></p>
Projects

More Related Content

ODP
Perl dancer
PDF
Rails Deployment with NginX
PPT
Web Scraper Shibuya.pm tech talk #8
PPT
루비가 얼랭에 빠진 날
PDF
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
PDF
Ember background basics
ODP
User Credential handling in Web Applications done right
KEY
Node workShop Basic
Perl dancer
Rails Deployment with NginX
Web Scraper Shibuya.pm tech talk #8
루비가 얼랭에 빠진 날
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
Ember background basics
User Credential handling in Web Applications done right
Node workShop Basic

What's hot (20)

KEY
Devsumi2012 攻めの運用の極意
PDF
konfigurasi freeradius + daloradius in debian 9
PDF
Ruby Postgres
ODP
Presentation of JSConf.eu
PDF
What the web platform (and your app!) can learn from Node.js
PDF
Automating Front-End Workflow
PDF
Puppet Camp 2012
PDF
Nginx + PHP
PDF
Two scoops of Django - Security Best Practices
KEY
Server side scripting smack down - Node.js vs PHP
PPTX
Оптимизация MySQL. Что должен знать каждый разработчик
PDF
Ecossistema Ruby - versão SCTI UNF 2013
PDF
"Mobage DBA Fight against Big Data" - NHN TE
ODP
Varnish: Making eZ Publish sites fly
PDF
Deploying Django with Ansible
PDF
HTTP For the Good or the Bad - FSEC Edition
PDF
Puppet Module Reusability - What I Learned from Shipping to the Forge
PDF
PLOG - Modern Javascripting with Plone
PPTX
Front End Development Tool Chain
PDF
Devsumi2012 攻めの運用の極意
konfigurasi freeradius + daloradius in debian 9
Ruby Postgres
Presentation of JSConf.eu
What the web platform (and your app!) can learn from Node.js
Automating Front-End Workflow
Puppet Camp 2012
Nginx + PHP
Two scoops of Django - Security Best Practices
Server side scripting smack down - Node.js vs PHP
Оптимизация MySQL. Что должен знать каждый разработчик
Ecossistema Ruby - versão SCTI UNF 2013
"Mobage DBA Fight against Big Data" - NHN TE
Varnish: Making eZ Publish sites fly
Deploying Django with Ansible
HTTP For the Good or the Bad - FSEC Edition
Puppet Module Reusability - What I Learned from Shipping to the Forge
PLOG - Modern Javascripting with Plone
Front End Development Tool Chain
Ad

Viewers also liked (8)

PPTX
Cross-lingual ontology lexicalisation, translation and information extraction...
PPTX
Cut psd to xthml
PPTX
Neo4j And The Benefits Of Graph Dbs 3
PPTX
kageyama-2550-0728.pptx
PPTX
Java on Windows Azure
PPTX
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
PPTX
S03 hybrid app_and_gae_datastore_v1.0
PPTX
NYC Hadoop Meetup - MapR, Architecture, Philosophy and Applications
Cross-lingual ontology lexicalisation, translation and information extraction...
Cut psd to xthml
Neo4j And The Benefits Of Graph Dbs 3
kageyama-2550-0728.pptx
Java on Windows Azure
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
S03 hybrid app_and_gae_datastore_v1.0
NYC Hadoop Meetup - MapR, Architecture, Philosophy and Applications
Ad

Similar to Ultra fast web development with sinatra (20)

PDF
Swing when you're winning - an introduction to Ruby and Sinatra
PPT
Intro to Ruby on Rails
PDF
Rails 2.3 and Rack - NHRuby Feb 2009
PPT
Ruby On Rails
PDF
Ruby on Rails Presentation
PDF
Using Sinatra to Build REST APIs in Ruby
PDF
Story for a Ruby on Rails Single Engineer
PPTX
Intro to Rails and MVC
PPT
Ruby On Rails Tutorial
PDF
Ruby w/o Rails (Олександр Сімонов)
PPT
An introduction-to-ruby-on-rails
PPT
An Introduction to Ruby on Rails 20100506
PDF
When To Use Ruby On Rails
PDF
Rails workshop for Java people (September 2015)
PPT
Intro to Rails ActiveRecord
PDF
Ambiguous Sinatra
PDF
Ambiguous Sinatra - Vadim Evseev
PPTX
Why Ruby?
PPT
Introduction To Ruby On Rails
ODP
RailswayCon 2010 - Dynamic Language VMs
Swing when you're winning - an introduction to Ruby and Sinatra
Intro to Ruby on Rails
Rails 2.3 and Rack - NHRuby Feb 2009
Ruby On Rails
Ruby on Rails Presentation
Using Sinatra to Build REST APIs in Ruby
Story for a Ruby on Rails Single Engineer
Intro to Rails and MVC
Ruby On Rails Tutorial
Ruby w/o Rails (Олександр Сімонов)
An introduction-to-ruby-on-rails
An Introduction to Ruby on Rails 20100506
When To Use Ruby On Rails
Rails workshop for Java people (September 2015)
Intro to Rails ActiveRecord
Ambiguous Sinatra
Ambiguous Sinatra - Vadim Evseev
Why Ruby?
Introduction To Ruby On Rails
RailswayCon 2010 - Dynamic Language VMs

More from Sérgio Santos (9)

PDF
Launching tech products
PPTX
Simple MongoDB design for Rails apps
PPTX
Rails + mongo db
PDF
Agoge - produtividade & multitasking
PDF
Ontologias
PDF
Workshop Django
PPTX
Gestão De Projectos
PDF
Django Vs Rails
PPTX
Gestor - Casos De Uso
Launching tech products
Simple MongoDB design for Rails apps
Rails + mongo db
Agoge - produtividade & multitasking
Ontologias
Workshop Django
Gestão De Projectos
Django Vs Rails
Gestor - Casos De Uso

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Spectroscopy.pptx food analysis technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
sap open course for s4hana steps from ECC to s4
Spectroscopy.pptx food analysis technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Ultra fast web development with sinatra