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

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
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
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Recently uploaded (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
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
 
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
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

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