emptygif
Langue: Français

Tous les langages et frameworks

Ruby on Rails Ruby

Un extrait Ruby pour Ruby on Rails qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Ruby on Rails Ruby

Installer
gem install rails && rails new app
Fichier
pixels_controller.rb
Lancer
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

Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.

Vérifier

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

Site officiel: Ruby on Rails

Autres extraits en Ruby