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)

ODP
Modern Perl
ODP
Exploiting the newer perl to improve your plugins
PPT
Web::Scraper
ODP
JUDCon London 2011 - Bin packing with drools planner by example
PDF
Capistrano2
ODP
Dynamic Tracing of your AMP web site
PDF
WordPress APIs
PDF
yusukebe in Yokohama.pm 090909
PDF
Osol Pgsql
PDF
PDF
Padrino is agnostic
PDF
More Secrets of JavaScript Libraries
PDF
Ten modules I haven't yet talked about
PDF
When To Use Ruby On Rails
PPT
Writing Friendly libraries for CodeIgniter
PDF
Logstash for SEO: come monitorare i Log del Web Server in realtime
ODP
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
PPT
What's New in ZF 1.10
ODP
Cena-DTA PHP Conference 2011 Slides
Modern Perl
Exploiting the newer perl to improve your plugins
Web::Scraper
JUDCon London 2011 - Bin packing with drools planner by example
Capistrano2
Dynamic Tracing of your AMP web site
WordPress APIs
yusukebe in Yokohama.pm 090909
Osol Pgsql
Padrino is agnostic
More Secrets of JavaScript Libraries
Ten modules I haven't yet talked about
When To Use Ruby On Rails
Writing Friendly libraries for CodeIgniter
Logstash for SEO: come monitorare i Log del Web Server in realtime
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
What's New in ZF 1.10
Cena-DTA PHP Conference 2011 Slides

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)

PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPT
Geologic Time for studying geology for geologist
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
STKI Israel Market Study 2025 version august
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPTX
The various Industrial Revolutions .pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PPTX
Modernising the Digital Integration Hub
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
observCloud-Native Containerability and monitoring.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Benefits of Physical activity for teenagers.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Geologic Time for studying geology for geologist
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Chapter 5: Probability Theory and Statistics
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
STKI Israel Market Study 2025 version august
A contest of sentiment analysis: k-nearest neighbor versus neural network
The various Industrial Revolutions .pptx
Tartificialntelligence_presentation.pptx
CloudStack 4.21: First Look Webinar slides
Getting started with AI Agents and Multi-Agent Systems
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
Modernising the Digital Integration Hub
Hindi spoken digit analysis for native and non-native speakers
Final SEM Unit 1 for mit wpu at pune .pptx

Ultra fast web development with sinatra