I’m using Sinatra’s set method in order to assign a global variable:
set :location, 'Melbourne'
I want to update this so that the variable is static or dynamic depending on whether the app is in development or production. I tried this below, which works in development, but not in production:
set :location, production? ? request.location.city : 'Melbourne'
The request.location.city is from the geolocation gem, and this method work fine in production in other situations. Is there something in the if statement that I’m missing, or does the Sinatra set method not accept statements?
Requestis not available at the top level, only inside request handlers.Write a method instead of a global setting, e.g.: