Last active
June 12, 2026 11:05
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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