Sinatra事始め
Upcoming SlideShare
Loading in...5
×
 

Sinatra事始め

on

  • 3,095 views

 

Statistics

Views

Total Views
3,095
Views on SlideShare
3,094
Embed Views
1

Actions

Likes
3
Downloads
14
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Sinatra事始め Sinatra事始め Presentation Transcript

    • 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