Share
Embed
The Lifecycle of a Rails Response
This breathtaking documentary series combines rare action, unimaginable scale, impossible locations and intimate moments captured from the deepest depths of Rails internals. Last year, we followed the lifecycle of best loved, wildest and most elusive Rails components through a request, from the browser to a controller action. This year, our journey takes us across the great text/plain, following the flow of HTTP streams, taking in the spectacular Action View as we find our way back to the browser. Join us to unearth the amazing lifecycle of a Rails response.
Krystan HuffMenne
May 04, 2020
Transcript
121 slides
-
https://skylight.io/r/railsconf Don’t struggle to learn why your app is slow.
Get answers with Skylight. DO THE ANSWER DANCE. SKYLIGHT -
app/controllers/hello_controller.rb Terminal $ Trying 34.194.84.73... Connected to ec2-34-194-84-73.compute-1.amazonaws.com. Escape character
is ‘^]’. > telnet 34.194.84.73 80 Picture: Masai Mara Wildlife / Matt Scobel / CC BY 3.0 -
app/controllers/hello_controller.rb class SafariController < ActionController::Base def hello # ...do stuff
here... render plain: 'Hello World' end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb Terminal $ Trying 34.194.84.73... Connected to ec2-34-194-84-73.compute-1.amazonaws.com. Escape character is ‘^]’. > telnet 34.194.84.73 80 GET /safari HTTP/1.1 > Host: skylight.io > Picture: Masai Mara Wildlife / Matt Scobel / CC BY 3.0 -
app/controllers/hello_controller.rb Terminal $ Trying 34.194.84.73... Connected to ec2-34-194-84-73.compute-1.amazonaws.com. Escape character
is ‘^]’. > telnet 34.194.84.73 80 GET /safari HTTP/1.1 > Host: skylight.io > < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length: 11 < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Hello World app/controllers/hello_controller.rb class SafariController < ActionController::Base def hello # ...do stuff here... render plain: 'Hello World' end end app/controllers/safari_controller.rb Picture: Three Elephants in Early Morning / Yu Miyawaki / CC BY 3.0 -
Sounds good. It’s a GET request for /safari, Host header
is skylight.io 200 OK. Content type is text/plain, body is “Roar Savanna”. Hey, I have a request for you to handle. -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb Terminal $ Trying 34.194.84.73... Connected to ec2-34-194-84-73.compute-1.amazonaws.com.
Escape character is ‘^]’. > telnet 34.194.84.73 80 -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb Terminal $ Trying 34.194.84.73... Connected to ec2-34-194-84-73.compute-1.amazonaws.com.
Escape character is ‘^]’. > telnet 34.194.84.73 80 GET /safari HTTP/1.1 > Host: skylight.io > -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb Terminal $ Trying 34.194.84.73... Connected to ec2-34-194-84-73.compute-1.amazonaws.com.
Escape character is ‘^]’. > telnet 34.194.84.73 80 < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length: 12 < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Roar Savanna GET /safari HTTP/1.1 > Host: skylight.io > Roar Savanna -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO'
=> ‘/safari', 'HTTP_HOST' => 'skylight.io', # ... } server.rb -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO'
=> ‘/safari', 'HTTP_HOST' => 'skylight.io', # ... } app.call(env) server.rb -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO'
=> ‘/safari', 'HTTP_HOST' => 'skylight.io', # ... } app.call(env) server.rb handwave handwave Check out last year's talk for more info! -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO'
=> ‘/safari', 'HTTP_HOST' => 'skylight.io', # ... } app.call(env) server.rb app/controllers/hello_controller.rb class SafariController < ActionController::Base def hello # Get it? A savanna is a type of plain... render plain: 'Roar Savanna' end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb http://skylight.io/safari app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO'
=> ‘/safari', 'HTTP_HOST' => 'skylight.io', # ... } status, headers, body = app.call(env) status # => 200 headers # => { 'Content-Type' => 'text/plain' } body # => [‘Roar Savanna’] server.rb 1 2 3 The Response Array -
app/controllers/hello_controller.rb http://skylight.io/safari Roar Savanna app/controllers/hello_controller.rb < HTTP/1.1 200 OK <
Content-Type: text/plain < Content-Length: 12 < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Roar Savanna -
app/controllers/hello_controller.rb http://skylight.io/safari Roar Savanna app/controllers/hello_controller.rb < HTTP/1.1 200 OK <
Content-Type: text/plain < Content-Length: 12 < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Roar Savanna -
app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => ‘/safari',
'HTTP_HOST' => 'skylight.io', # ... } status, headers, body = app.call(env) status # => 200 headers # => { 'Content-Type' => 'text/plain' } body # => [‘Roar Savanna’] server.rb 1 The Response Array -
1xx — 2xx — 3xx — 4xx — 5xx —
STATUS CODES Informational Success!! Redirection Client Error Server Error -
Here’s a GET request for /safari, Host header is skylight.io
OMG I DID IT! Roar Savanna! Huh? -
Great, I can render that. Here’s a GET request for
/safari, Host header is skylight.io 200 OK; Roar Savanna -
Should I index the page at /safari ? 500 Internal
Server Error OK, I’ll be back later! … How about now? 200 OK; Roar Savanna Great! I’ve indexed it. -
1xx — 2xx — 3xx — 4xx — 5xx —
STATUS CODES Informational Success!! Redirection Client Error Server Error PRO-TIP! Learn a lot more about status codes by going to httpstatuses.com -
app/controllers/hello_controller.rb class SafariController < ApplicationController def eat_hippo consume_hippo if @current_user.lion?
head :no_content # 204 end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController def eat_hippo consume_hippo if @current_user.lion?
head :no_content # 204 end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController def eat_hippo consume_hippo if @current_user.lion?
head :no_content # 204 end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController def eat_hippo consume_hippo if @current_user.lion?
head :no_content # 204 end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController def eat_hippo consume_hippo if @current_user.lion?
head :no_content # 204 end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} before_action { redirect_to oasis_url if dry_season? } def find_hippo render :hippo end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} before_action { redirect_to oasis_url if dry_season? } def find_hippo render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 302 Found < Location: https://www.skylight.io/oasis < Content-Type: text/plain < Date: Thu, 25 Apr 2019 18:52:54 GMT -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo redirect_to oasis_url, status: :moved_permanently end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 301 Moved Permanently < Location: https://www.skylight.io/oasis < Content-Type: text/plain < Date: Thu, 25 Apr 2019 18:52:54 GMT -
app/controllers/hello_controller.rb Rails.application.routes.draw do get '/find-hippo', to: redirect('/oasis') end config/routes.rb app/controllers/hello_controller.rb
< HTTP/1.1 301 Moved Permanently < Location: https://www.skylight.io/oasis < Content-Type: text/plain < Date: Thu, 25 Apr 2019 18:52:54 GMT -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo redirect_to oasis_url if dry_season? render :hippo end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo redirect_to oasis_url if dry_season? render :hippo end end app/controllers/safari_controller.rb http://skylight.io/find-hippo -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} before_action { redirect_to oasis_url if dry_season? } def find_hippo render :hippo end end app/controllers/safari_controller.rb -
Here’s a GET request for /safari, Host header is skylight.io
200 OK; Roar Savanna Great, I can render that. Wait…I need more information. -
Here’s a GET request for /safari, Host header is skylight.io
200 OK; Roar Savanna Great, I can render that. Wait…I need more information. Oh yeah. It’s a plain text response. Oh! OK! -
app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => ‘/safari',
'HTTP_HOST' => 'skylight.io', # ... } status, headers, body = app.call(env) status # => 200 headers # => { 'Content-Type' => 'text/plain' } body # => [‘Roar Savanna’] server.rb 1 2 The Response Array -
app/controllers/hello_controller.rb < HTTP/1.1 302 Found < Content-Type: text/plain < Location:
https://www.skylight.io/oasis < Date: Thu, 25 Apr 2019 18:52:54 GMT -
app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length:
12 < Set-Cookie: _safari_session=some-token; < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Roar Savanna -
app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length:
12 < Set-Cookie: _safari_session=some-token; < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Roar Savanna -
app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length:
12 < Set-Cookie: _safari_session=some-token; < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Roar Savanna -
app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/plain < Content-Length:
12 < Set-Cookie: _safari_session=some-token; < Date: Thu, 25 Apr 2019 18:52:54 GMT < < Roar Savanna -
Here’s a GET request for /safari, Host header is skylight.io
… 200 OK; Roar Savanna Thanks! -
Here’s a GET request for /safari, Host header is skylight.io
200 OK; Roar Savanna Here’s a GET request for /safari, Host header is skylight.io Just use the last 200 Nice! Thanks! -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb PRO-TIP! Turn on caching in development by running rails dev:cache -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo http_cache_forever { render :hippo } end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=3155695200, private < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo http_cache_forever { render :hippo } end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=3155695200, private < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo http_cache_forever(public: true) { render :hippo } end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=3155695200, public < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo http_cache_forever { render :hippo } end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=3155695200, private < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo expires_in 1.hour render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=3600, private < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo expires_in 1.hour render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=3600, private < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=0, private, must-revalidate < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=0, private, must-revalidate < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb <!DOCTYPE html> <html> <head> <title>Safari</title> <link rel="stylesheet" media=“all" href="/assets/application-gobbledygook.css" /> <script src="/packs/js/application-gobbledygook.js"></script> </head> <body> -
app/controllers/hello_controller.rb # a simplified Rack::ETag module Rack class ETag def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 digest = digest_body(body) headers[Etag] = %(W/"#{digest}") end [status, headers, body] end private #... end end rack/lib/rack/etag.rb -
app/controllers/hello_controller.rb # a simplified Rack::ETag module Rack class ETag def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 digest = digest_body(body) headers[Etag] = %(W/"#{digest}") end [status, headers, body] end private #... end end rack/lib/rack/etag.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=0, private, must-revalidate < ETag: W/“48a7e47309e0ec54e32df3a272094025" < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control:
max-age=0, private, must-revalidate < ETag: W/“48a7e47309e0ec54e32df3a272094025" < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> app/controllers/hello_controller.rb > GET /find-hippo HTTP/1.1 > Host: skylight.io > If-None-Match: W/"48a7e47309e0ec54e32df3a272094025" -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb <!DOCTYPE html> <html> <head> <title>Safari</title> <link rel="stylesheet" media=“all" href="/assets/application-gobbledygook.css" /> <script src="/packs/js/application-gobbledygook.js"></script> </head> <body> -
app/controllers/hello_controller.rb # a simplified Rack::ETag module Rack class ETag def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 digest = digest_body(body) headers[Etag] = %(W/"#{digest}") end [status, headers, body] end private #... end end rack/lib/rack/etag.rb -
app/controllers/hello_controller.rb # a simplified Rack::ETag module Rack class ETag def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 digest = digest_body(body) headers[Etag] = %(W/"#{digest}") end [status, headers, body] end private #... end end rack/lib/rack/etag.rb -
app/controllers/hello_controller.rb # a simplified Rack::ETag module Rack class ETag def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 digest = digest_body(body) headers[Etag] = %(W/"#{digest}") end [status, headers, body] end private #... end end rack/lib/rack/etag.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=0, private, must-revalidate < ETag: W/“48a7e47309e0ec54e32df3a272094025" < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb # a simplified Rack::ConditionalGet module Rack class ConditionalGet def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 && etag_matches? status = 304 body = [] end [status, headers, body] end private def etag_matches? headers['ETag'] == env['HTTP_IF_NONE_MATCH'] end end end rack/lib/rack/conditional_get.rb -
app/controllers/hello_controller.rb # a simplified Rack::ConditionalGet module Rack class ConditionalGet def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 && etag_matches? status = 304 body = [] end [status, headers, body] end private def etag_matches? headers['ETag'] == env['HTTP_IF_NONE_MATCH'] end end end rack/lib/rack/conditional_get.rb app/controllers/hello_controller.rb < HTTP/1.1 304 Not Modified < Cache-Control: max-age=0, private, must-revalidate < ETag: W/“48a7e47309e0ec54e32df3a272094025” < Content-Type: text/html < Date: Thu, 25 Apr 2019 18:52:54 GMT < -
app/controllers/hello_controller.rb # a simplified Rack::ConditionalGet module Rack class ConditionalGet def
initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) if status == 200 && etag_matches? status = 304 body = [] end [status, headers, body] end private def etag_matches? headers['ETag'] == env['HTTP_IF_NONE_MATCH'] end end end rack/lib/rack/conditional_get.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Cache-Control: max-age=0, private, must-revalidate < ETag: W/“48a7e47309e0ec54e32df3a272094025” < Content-Type: text/html < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo if stale?(@hippo) end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=0, private, must-revalidate < ETag: W/“48a7e47309e0ec54e32df3a272094025" < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=0, private, must-revalidate < ETag: W/"60bee75b8031cda7761a332685151766" < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb <!DOCTYPE html> <html> <head> <title>Safari</title> <link rel="stylesheet" media=“all" href="/assets/application-gobbledygook.css"
/> <script src="/packs/js/application-gobbledygook.js"></script> </head> <body> </body> </html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo if stale?(@hippo) end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: max-age=0, private, must-revalidate < ETag: W/"60bee75b8031cda7761a332685151766" < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo response.headers["Cache-Control"] = "no-store" render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: no-store < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo response.headers["Cache-Control"] = "no-store" render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Cache-Control: no-store < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> no-store ≠ no-cache -
app/controllers/hello_controller.rb env = { 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => ‘/safari',
'HTTP_HOST' => 'skylight.io', # ... } status, headers, body = app.call(env) status # => 200 headers # => { 'Content-Type' => 'text/plain' } body # => [‘Roar Savanna’] server.rb 1 2 3 The Response Array -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb <!DOCTYPE html> <html> <head> <title>Safari</title> <link rel="stylesheet" media=“all" href="/assets/application-gobbledygook.css" /> <script src="/packs/js/application-gobbledygook.js"></script> </head> <body> -
app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Date:
Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb > GET /find-hippo HTTP/1.1 > Host: skylight.io > Accept:
text/html,application/xhtml+xml,application/xml; -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo respond_to do |format| format.html { render :hippo } format.json { render json: @hippo } end end end app/controllers/safari_controller.rb -
http://skylight.io/find-hippo { "id": 1, "name": "Jason", "created_at": "2020-04-10T17:14:20.771Z", "updated_at": "2020-04-10T17:14:20.771Z"
} app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Cache-Control: max-age=0, private, must-revalidate < Date: Thu, 25 Apr 2019 18:52:54 GMT < Content-Type: application/json < < {"id": 1, "name": “Jason", … } -
app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < X-Content-Type-Options:
nosniff < Cache-Control: max-age=0, private, must-revalidate < Date: Thu, 25 Apr 2019 18:52:54 GMT < < <html>…</html> -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb -
app/controllers/hello_controller.rb class SafariController < ApplicationController before_action { @hippo = Hippo.first
} def find_hippo render :hippo end end app/controllers/safari_controller.rb app/controllers/hello_controller.rb Hey <%= current_user.name %>, meet <%= link_to @hippo.name, @hippo %>! app/views/safari/hippo.html.erb -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end NOTE: To see the actual code, look in ActionView!::Rendering, ActionView!::Base, ActionView!::Renderer, ActionView!::TemplateRenderer, ActionView!::Template -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
app/controllers/hello_controller.rb class SafariControllerViewContext < ActionView::Base include Rails::AllTheHelpers # link_to, etc.
include MyApp::AllTheHelpers # current_user, etc. def initialize(assigns) assigns.each { |k, v| instance_variable_set("@#{k}", v) } end private # Hey <%= current_user.name %>, meet # <%= link_to @hippo.name, @hippo %>! def __compiled_app_templates_hippo_erb output = "" output << "Hey " output << html_escape(current_user.name) output << ", meet" output << link_to(html_escape(@hippo.name), @hippo) output << "!" output end end -
http://skylight.io/find-hippo <!DOCTYPE html> <html> <head> <title>Safari</title> <link rel="stylesheet" media="all" href="/assets/application-gobbledygook.css"
/> <script src="/packs/js/application-gobbledygook.js"></script> </head> <body> Hey RailsConf, meet <a href="/hippos/1">Phyllis</a>! </body> </html> Hey RailsConf, meet Phyllis! -
http://skylight.io/find-hippo <!DOCTYPE html> <html> <head> <title>Safari</title> <link rel="stylesheet" media="all" href="/assets/application-gobbledygook.css"
/> <script src="/packs/js/application-gobbledygook.js"></script> </head> <body> Hey RailsConf, meet <a href="/hippos/1">Phyllis</a>! </body> </html> Hey RailsConf, meet Phyllis! app/controllers/hello_controller.rb < HTTP/1.1 200 OK < Content-Type: text/html < Content-Length: 306 < Cache-Control: max-age=0, private, must-revalidate < ETag: W/“60bee75b8031cda7761a332685151766” < Set-Cookie: _safari_session=some-session-token; path=/; < X-Content-Type-Options: nosniff < Date: Thu, 25 Apr 2019 18:52:54 GMT