gpt4 book ai didi

ruby - 如何从 Padrino 中的模型访问应用程序设置

转载 作者:数据小太阳 更新时间:2023-10-29 07:35:58 28 4
gpt4 key购买 nike

我正尝试在 Padrino 中做一些基本的事情,但是大量的搜索都没有找到任何答案。我正在尝试从模型访问全局设置。我在 environments.yaml 文件的“开发”部分添加了一行名为“端点”的行,如何从模型类访问此设置? environments.yaml 是用于此类设置的最佳文件吗?

environments:
development:
endpoint: 'http://192.168.56.1:3001'

当我尝试在模型函数中使用“settings.endpoint”时,出现错误:

undefined local variable or method `settings' for Country:Class

最佳答案

如果我是你,我会使用环境变量:

environments:
development:
endpoint: <%= ENV["ENDPOINT"] %>

然后在您的 ruby​​ 代码中,您可以使用 ENV['ENDPOINT'] 访问它。

查看如何使用 gem(例如 Dotenv)在 .env 文件中设置环境变量.

关于ruby - 如何从 Padrino 中的模型访问应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24923171/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com