SlideShare a Scribd company logo
1 of 21
SINATRA
simple way to make web application
•   ( Sixeight )

•


•


•
•Sinatra   ?

•

•

•
SINATRA   ?


Web
SINATRA         ?
• Web              DSL

• Rack   Rails

•
DSL

require ‘rubygems’
require ‘sinatra’


get ‘/hi’ do
  ‘Hello World!’
end
                     app.rb
DSL
> ruby app.rb
== Sinatra/0.9.2 has taken the stage on 4567 for development with backup from Thin
>> Thin web server (v1.2.2 codename I Find Your Lack of Sauce Disturbing)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567, CTRL+C to stop
RACK   RAILS

• Rails

•         Rack
RACK             RAILS

• Rails

•         Rack



                 Sinatra
• View   /

 • Haml,      Erb, Builder, Sass

• Model      / OR

 • Sequel,     DataMapper, ActiveRecord, etc
• Routes

• Template

• Configuration

• Error   handling
• Helpers
ROUTES
•get(‘/’)   { ...            ... }

•post(‘/’)    { ..,              ... }

•put(‘/’)   { ...            ... }

•delete(‘/’)        { ...            ... }
ROUTES
• ‘/hi‘      Route

•                                URL
    •




• HTTP                 (GET, POST, PUT, DLETE)

    • get(‘/hi’)   { ... } != put(‘/hi’) { ... }
ROUTES
•                            ‘/show/:id’
    • /show/5    #=> params[:id] == 5
•                                %r|/hello/(w{3})|
    • /hello/tomohiro    #=> params[:captures][0] == ‘tom’
•

    • get   '/foo', :agent => /Songbird (d.d)[d/]*?/
TEMPLATE
•

    • haml, erb, builder, sass

•                        ./views
    • set   :views, File.dirname(__FILE__) + '/templates'

• ./views/layout.[type]

    • e.g.)   ./views/layout.haml

    • haml    :index, :layout => false #=>
CONFIGURATION
•   set
    • set   :max_length, 15 #=> options.max_length == 15

•                       enable, disable
    • enable   :sessions #=> options.sessions == true

•                         (development, product, test)
    • configure(:production)   { enable :log }
ERROR HANDLING

•                                    (404 Not Found)
    • not_found     { ‘404            ’}

•                            error
    • error   {‘                             ’}
    • error(MyError)    { ‘MyError         : } # raise MyError

•             production
HELPERS
• helpers

    helpers do
      def mr(name)
        “Mr. #{name}”
      end
    end

•

    get ‘/hello/:name’ do |name|
      “hello, #{mr(name)}”
    end
• Web

 • http://www.sinatrarb.com/

• Repository

 • http://github.com/sinatra/sinatra/tree/master

• Issue   tracker
 • https://sinatra.lighthouseapp.com/projects/9779-sinatra

• Mailing   List
 • http://groups.google.com/group/sinatrarb
Sinatra事始め

More Related Content

Similar to Sinatra事始め

Go Web Development
Go Web DevelopmentGo Web Development
Go Web DevelopmentCheng-Yi Yu
 
Kamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With StyleKamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With StyleDaniel-Constantin Mierla
 
Keeping It Small with Slim
Keeping It Small with SlimKeeping It Small with Slim
Keeping It Small with SlimRaven Tools
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkJeremy Kendall
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launchedMat Schaffer
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちRyo Miyake
 
Short lived immutable servers with masterless puppet
Short lived immutable servers with masterless puppetShort lived immutable servers with masterless puppet
Short lived immutable servers with masterless puppetNeil Millard
 
PTW Rails Bootcamp
PTW Rails BootcampPTW Rails Bootcamp
PTW Rails BootcampMat Schaffer
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkJeremy Kendall
 
SCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud Infrastructure
SCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud InfrastructureSCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud Infrastructure
SCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud InfrastructureMatt Ray
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyLaunchAny
 
Manage and Deploy your sites with Drush
Manage and Deploy your sites with DrushManage and Deploy your sites with Drush
Manage and Deploy your sites with DrushAmazee Labs
 

Similar to Sinatra事始め (20)

Go Web Development
Go Web DevelopmentGo Web Development
Go Web Development
 
Kamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With StyleKamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With Style
 
Keeping It Small with Slim
Keeping It Small with SlimKeeping It Small with Slim
Keeping It Small with Slim
 
Keeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro frameworkKeeping it small: Getting to know the Slim micro framework
Keeping it small: Getting to know the Slim micro framework
 
Sinatra slideshare
Sinatra slideshareSinatra slideshare
Sinatra slideshare
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launched
 
DBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たちDBIx::Skinnyと仲間たち
DBIx::Skinnyと仲間たち
 
Sinatra
SinatraSinatra
Sinatra
 
Short lived immutable servers with masterless puppet
Short lived immutable servers with masterless puppetShort lived immutable servers with masterless puppet
Short lived immutable servers with masterless puppet
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Beginner's Sinatra
Beginner's SinatraBeginner's Sinatra
Beginner's Sinatra
 
PTW Rails Bootcamp
PTW Rails BootcampPTW Rails Bootcamp
PTW Rails Bootcamp
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
router-simple.cr
router-simple.crrouter-simple.cr
router-simple.cr
 
Infra@LINE_Chris
Infra@LINE_ChrisInfra@LINE_Chris
Infra@LINE_Chris
 
SCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud Infrastructure
SCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud InfrastructureSCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud Infrastructure
SCALE12X Build a Cloud Day: Chef: The Swiss Army Knife of Cloud Infrastructure
 
Tabledown
TabledownTabledown
Tabledown
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Manage and Deploy your sites with Drush
Manage and Deploy your sites with DrushManage and Deploy your sites with Drush
Manage and Deploy your sites with Drush
 

More from Tomohiro Nishimura

逃げ道をなくすということについて、僕の持っている知見を話します。
逃げ道をなくすということについて、僕の持っている知見を話します。逃げ道をなくすということについて、僕の持っている知見を話します。
逃げ道をなくすということについて、僕の持っている知見を話します。Tomohiro Nishimura
 
シュッとふりかえる Ruby 2.0 以降
シュッとふりかえる Ruby 2.0 以降シュッとふりかえる Ruby 2.0 以降
シュッとふりかえる Ruby 2.0 以降Tomohiro Nishimura
 
DSLについて語るときに僕の語ること
DSLについて語るときに僕の語ることDSLについて語るときに僕の語ること
DSLについて語るときに僕の語ることTomohiro Nishimura
 
Rubyist のための HTML5 入門 -Content Models-
Rubyist のための HTML5 入門 -Content Models-Rubyist のための HTML5 入門 -Content Models-
Rubyist のための HTML5 入門 -Content Models-Tomohiro Nishimura
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法Tomohiro Nishimura
 
It's Mechanize for it. Ruby as a Finder.
It's Mechanize for it. Ruby as a Finder.It's Mechanize for it. Ruby as a Finder.
It's Mechanize for it. Ruby as a Finder.Tomohiro Nishimura
 
Haml/Sassを使って履歴書を書くためのn個の方法
Haml/Sassを使って履歴書を書くためのn個の方法Haml/Sassを使って履歴書を書くためのn個の方法
Haml/Sassを使って履歴書を書くためのn個の方法Tomohiro Nishimura
 

More from Tomohiro Nishimura (20)

逃げ道をなくすということについて、僕の持っている知見を話します。
逃げ道をなくすということについて、僕の持っている知見を話します。逃げ道をなくすということについて、僕の持っている知見を話します。
逃げ道をなくすということについて、僕の持っている知見を話します。
 
シュッとふりかえる Ruby 2.0 以降
シュッとふりかえる Ruby 2.0 以降シュッとふりかえる Ruby 2.0 以降
シュッとふりかえる Ruby 2.0 以降
 
DSLについて語るときに僕の語ること
DSLについて語るときに僕の語ることDSLについて語るときに僕の語ること
DSLについて語るときに僕の語ること
 
Atom ことはじめ
Atom ことはじめAtom ことはじめ
Atom ことはじめ
 
The way to the Kyoto.rb
The way to the Kyoto.rbThe way to the Kyoto.rb
The way to the Kyoto.rb
 
Kyotorb#4
Kyotorb#4Kyotorb#4
Kyotorb#4
 
Kyotorb#3
Kyotorb#3Kyotorb#3
Kyotorb#3
 
Kyotorb Meetup #2
Kyotorb Meetup #2Kyotorb Meetup #2
Kyotorb Meetup #2
 
Kyoto.rb
Kyoto.rbKyoto.rb
Kyoto.rb
 
2010年ふりかえる
2010年ふりかえる2010年ふりかえる
2010年ふりかえる
 
Rubyist のための HTML5 入門 -Content Models-
Rubyist のための HTML5 入門 -Content Models-Rubyist のための HTML5 入門 -Content Models-
Rubyist のための HTML5 入門 -Content Models-
 
NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法NoSQL を Ruby で実践するための n 個の方法
NoSQL を Ruby で実践するための n 個の方法
 
Boys, do LiveCoding
Boys, do LiveCodingBoys, do LiveCoding
Boys, do LiveCoding
 
Introduce the LiveCoding
Introduce the LiveCodingIntroduce the LiveCoding
Introduce the LiveCoding
 
It's Mechanize for it. Ruby as a Finder.
It's Mechanize for it. Ruby as a Finder.It's Mechanize for it. Ruby as a Finder.
It's Mechanize for it. Ruby as a Finder.
 
Lazyselect
LazyselectLazyselect
Lazyselect
 
Introduce the Hacobu
Introduce the HacobuIntroduce the Hacobu
Introduce the Hacobu
 
Introduce RSpec's Matchers
Introduce RSpec's MatchersIntroduce RSpec's Matchers
Introduce RSpec's Matchers
 
Termtter Refactoring Spa
Termtter Refactoring SpaTermtter Refactoring Spa
Termtter Refactoring Spa
 
Haml/Sassを使って履歴書を書くためのn個の方法
Haml/Sassを使って履歴書を書くためのn個の方法Haml/Sassを使って履歴書を書くためのn個の方法
Haml/Sassを使って履歴書を書くためのn個の方法
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Sinatra事始め

  • 1. SINATRA simple way to make web application
  • 2. ( Sixeight ) • • •
  • 3. •Sinatra ? • • •
  • 4. SINATRA ? Web
  • 5. SINATRA ? • Web DSL • Rack Rails •
  • 6. DSL require ‘rubygems’ require ‘sinatra’ get ‘/hi’ do ‘Hello World!’ end app.rb
  • 7. DSL > ruby app.rb == Sinatra/0.9.2 has taken the stage on 4567 for development with backup from Thin >> Thin web server (v1.2.2 codename I Find Your Lack of Sauce Disturbing) >> Maximum connections set to 1024 >> Listening on 0.0.0.0:4567, CTRL+C to stop
  • 8. RACK RAILS • Rails • Rack
  • 9. RACK RAILS • Rails • Rack Sinatra
  • 10. • View / • Haml, Erb, Builder, Sass • Model / OR • Sequel, DataMapper, ActiveRecord, etc
  • 11. • Routes • Template • Configuration • Error handling • Helpers
  • 12. ROUTES •get(‘/’) { ... ... } •post(‘/’) { .., ... } •put(‘/’) { ... ... } •delete(‘/’) { ... ... }
  • 13. ROUTES • ‘/hi‘ Route • URL • • HTTP (GET, POST, PUT, DLETE) • get(‘/hi’) { ... } != put(‘/hi’) { ... }
  • 14. ROUTES • ‘/show/:id’ • /show/5 #=> params[:id] == 5 • %r|/hello/(w{3})| • /hello/tomohiro #=> params[:captures][0] == ‘tom’ • • get '/foo', :agent => /Songbird (d.d)[d/]*?/
  • 15. TEMPLATE • • haml, erb, builder, sass • ./views • set :views, File.dirname(__FILE__) + '/templates' • ./views/layout.[type] • e.g.) ./views/layout.haml • haml :index, :layout => false #=>
  • 16. CONFIGURATION • set • set :max_length, 15 #=> options.max_length == 15 • enable, disable • enable :sessions #=> options.sessions == true • (development, product, test) • configure(:production) { enable :log }
  • 17. ERROR HANDLING • (404 Not Found) • not_found { ‘404 ’} • error • error {‘ ’} • error(MyError) { ‘MyError : } # raise MyError • production
  • 18. HELPERS • helpers helpers do def mr(name) “Mr. #{name}” end end • get ‘/hello/:name’ do |name| “hello, #{mr(name)}” end
  • 19.
  • 20. • Web • http://www.sinatrarb.com/ • Repository • http://github.com/sinatra/sinatra/tree/master • Issue tracker • https://sinatra.lighthouseapp.com/projects/9779-sinatra • Mailing List • http://groups.google.com/group/sinatrarb