emptygif
Wika: Filipino

Lahat ng language at framework

Ruby on Rails Ruby

Isang Ruby snippet para sa Ruby on Rails na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Ruby on Rails Ruby

I-install
gem install rails && rails new app
File
pixels_controller.rb
Patakbuhin
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

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: Ruby on Rails

Iba pa sa Ruby