Ruby on Rails Ruby
Ein Ruby-Snippet für Ruby on Rails, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.
Ruby on Rails Ruby
# app/controllers/pixels_controller.rb
# ActionController::API: no session, cookies or browser-version checks for a beacon.
class PixelsController < ActionController::API
GIF = "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==".unpack1("m0").freeze
def show
no_store
send_data GIF, type: "image/gif", disposition: "inline"
end
end
# config/routes.rb
Rails.application.routes.draw do
get "/pixel.gif", to: "pixels#show", format: false
end
Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.
Prüfen
curl -sI http://localhost:8080/pixel.gif
Offizielle Website: Ruby on Rails