Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav
Last active June 12, 2026 11:05
Show Gist options
  • Select an option

  • Save poudelmadhav/99d66aece9b95673e7ddce2c4fbc5895 to your computer and use it in GitHub Desktop.

Select an option

Save poudelmadhav/99d66aece9b95673e7ddce2c4fbc5895 to your computer and use it in GitHub Desktop.
A zero-dependency Ruby on Rails implementation to redirect users to the Apple App Store or Google Play Store using User-Agent matching.
class DownloadsController < ApplicationController
APP_STORE_URL = "https://apps.apple.com/us/app/google/id284815942".freeze
PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox".freeze
def show
if apple_device?
redirect_to APP_STORE_URL, allow_other_host: true
else
redirect_to PLAY_STORE_URL, allow_other_host: true
end
end
private
def apple_device?
request.user_agent.to_s.match?(/iPhone|iPad|iPod|Mac/)
end
end
Rails.application.routes.draw do
resource :download, only: :show
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment