emptygif
Language: English

All languages and frameworks

Ruby on Rails Ruby

A Ruby snippet for Ruby on Rails that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Ruby on Rails Ruby

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

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Ruby on Rails

More in Ruby