How to put Rails environment variable in apple-app-site-association file for universal links?

Viewed 1168

So currently I have inside the public folder a file called "apple-app-site-association" with the content:

{"applinks":{"apps":[],"details":[{"appID":"{#Rails.configuration.appID}","paths":"*"}]}}

Obviously the {#Rails.configuration.appID} is not being generated dynamically and is being output literally, but I would like it to be reading from the config file, where appID is defined. How can I go about this??

1 Answers

The most straightforward way would be to just add a route.

get '/apple-app-site-association' => 'pages#apple_app_site_association'

def apple_app_site_association
  render :json => {"applinks":{"apps":[],"details":[{"appID": Rails.configuration.appID,"paths":"*"}]}}
end

You may need to do more than that, but that should at least get you moving in the right direction.

Update 2020: Typo in route path fixed

Related