Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rack is Spectacular
Search
Bryce "BonzoESC" Kerley
February 21, 2010
Programming
73
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rack is Spectacular
Barcamp Miami 2010
Bryce "BonzoESC" Kerley
February 21, 2010
More Decks by Bryce "BonzoESC" Kerley
See All by Bryce "BonzoESC" Kerley
Ruby in 2020
bryce
1
130
Rails and the Internet of Things
bryce
1
94
It's Not Ruby, But…
bryce
0
91
Ruby 2.5: What's New and What's Cool
bryce
0
99
docker for rubyists
bryce
0
130
Would You Like To Make A Game?
bryce
0
69
WebSockets and ActionCable
bryce
0
97
How I Learned to Stop Worrying and Like RSpec
bryce
0
95
How Do Computers Even Work?
bryce
1
230
Other Decks in Programming
See All in Programming
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
700
Java 27新機能 / Java 27 new features
kishida
2
120
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
6
1.8k
Intent as Code
shoppingjaws
6
980
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.1k
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
320
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
110
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
370
【DroidKaigi 2026】「アクセシビリティを利用するとき、 アクセシビリティもまたこちらを利用している」 〜マルウェアによる攻撃と防衛について〜
halunoyo
0
460
Security issues being discussed on Web Platforms
petamoriken
0
880
Webの地図
yosuke_furukawa
PRO
6
4.4k
業務時間外もAIに働いてもらう話
colorful12
3
10k
Featured
See All Featured
Game over? The fight for quality and originality in the time of robots
wayneb77
1
270
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
690
A Modern Web Designer's Workflow
chriscoyier
699
190k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Writing Fast Ruby
sferik
630
63k
Docker and Python
trallard
47
4.2k
Amusing Abliteration
ianozsvald
1
300
[SF Ruby Conf 2025] Rails X
palkan
2
1.4k
The Invisible Side of Design
smashingmag
301
52k
Discover your Explorer Soul
emna__ayadi
2
1.3k
GraphQLとの向き合い方2022年版
quramy
50
15k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Transcript
Rack is Spectacular Learning Rack by making a cheap Rails
knockoff
WARNING CODE HEAVY HTTP Ruby Rails
WARNING CODE HEAVY So get the code http://bit.ly/spectac c9c340bb
WARNING CODE HEAVY NOT READY FOR PRODUCTION c9c340bb
Rack • Standard Ruby-HTTP interface • Write (framework) once •
Run anywhere (that is Rack-compatible) • Rails, Sinatra, Camping • Mongrel, Passenger, Unicorn
A Rack Application use Rack::ContentLength run(proc do [ 200, {
'Content-type' => 'text/plain'}, 'hello world'] end) Response Code Response Headers Response Body c9c340bb config.ru
None
What is Rails • ActionPack • Router - maps URLs
to code • Controller - environment for code • View - generating response body • ActiveRecord - database access
The Essential Rails • ActionPack • Router - maps URLs
to code • Controller - environment for code • View - generating response body • ActiveRecord - database access
module Spectacular class App def call(environment) [ 200, { 'Content-type'
=> 'text/plain'}, 'hello world'] end end end require 'lib/spectacular.rb' use Rack::ContentLength run(Spectacular::App.new) config.ru lib/spectacular/app.rb 0fad6a02
None
module Spectacular class App … def call(environment) method = environment['REQUEST_METHOD']
path = environment['PATH_INFO'] @dispatcher.dispatch method, path, environment rescue => exception error_backtrace exception, environment end private def error_backtrace(exception, environment) exception_info = “some html” [500, { 'Content-type' => 'text/html'}, exception_info] end … end end lib/spectacular/app.rb 2a0d1445 breaks; no dispatcher yet
None
Dispatch & Routing are the most complicated parts of Rails
[citation needed]
But That’s Okay • We’re not building Rails • It’s
okay if we Fail to Scale • Just use an array to map paths to controllers and actions
def get_route(path) @routes.detect{ |r| path === r[0] } end …
class RoutePen def route(path, controller, method) @routes << [path, controller, method] end end 9cfb9609 lib/spectacular/dispatcher.rb
None
def response_for(method) @method = method send @method [response_code, headers, body]
end … def template_file File.join(APP_DIR, 'views', controller_name, "#{@method}.html.haml") end … def body return @body if defined? @body template = File.read template_file engine = Haml::Engine.new template @body = engine.render end ce2f00a3 lib/spectacular/controller.rb
class HelloController < Spectacular::Controller def index end end hello world
app/controllers/hello_controller.rb app/views/hello/index.html.haml ce2f00a3
None
Wildcards def get_route(path) @routes.detect{ |r| r[0] === path } end
lib/spectacular/dispatcher.rb 48b08205
=== 0 :> /abc/ === 'abc' # => true 0
:> String === 'abc' # => true 0 :> /too+t/ === 'toooooooooot' # => true
route /too+t/, TootController, :toot app/routes.rb A Wildcard Route 48b08205
Using the Path class TootController < Spectacular::Controller def toot @toot
= @path.gsub('/','') end end app/controllers/toot_controller.rb %h1=@toot app/views/toot/toot.html.haml 48b08205
None
None
404 • When we can’t figure out how to process
a request, that should be a “404” • We can simply make a wildcard route
route //, ErrorController, :not_found app/routes.rb class ErrorController < Spectacular::Controller def
not_found @response_code = 404 end end app/controllers/error_controller.rb 2a2653b2
None
What’s Left • Only renders HAML • No layouts •
Can’t easily render a different view • No query parameters • No POST
thanks • Bryce Kerley; mercenary developer •
[email protected]
• http://twitter.com/bonzoesc
• Code on Github: http://bit.ly/spectac