如何根据生产或开发环境在 Sinatra 中设置全局变量?
我正在使用 Sinatra 的 set
方法来分配全局变量:
set :location, 'Melbourne'
我想更新它,以便该变量是静态的或动态的,具体取决于应用程序是处于开发阶段还是生产阶段。我在下面尝试了这个,它在开发中有效,但在生产中不起作用:
set :location, production? ? request.location.city : 'Melbourne'
request.location.city
来自地理定位 gem,并且此方法在其他情况下在生产中运行良好。 if
语句中是否缺少某些内容,或者 Sinatra set
方法不接受语句?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Request
在顶层不可用,只能在请求处理程序中使用。编写一个方法而不是全局设置,例如:
Request
is not available at the top level, only inside request handlers.Write a method instead of a global setting, e.g.: