emptygif
Dil: Türkçe

Tüm diller ve framework'ler

Ruby on Rails Ruby

Ruby on Rails için, /pixel.gif isteklerine başlangıçta bir kez çözülen boş GIF ile yanıt veren bir Ruby örneği.

Ruby on Rails Ruby

Kurulum
gem install rails && rails new app
Dosya
pixels_controller.rb
Çalıştır
bin/rails server -p 8080
# 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

Bu örneği çalıştırıp döndürdüğü baytları karşılaştırdık.

Kontrol et

curl -sI http://localhost:8080/pixel.gif

Resmî site: Ruby on Rails

Ruby için daha fazlası