如何访问帮助文件中的配置变量?
How do I access my config variable in my helper file?
我正在使用 rails 5。我在我的 config/environments/development.rb 文件中定义了这个
config.hostname = “myapp.com"
然后我尝试使用
在帮助文件中访问它
url = "https://#{config.hostname}/lti"
但这会导致错误,
NameError: undefined local variable or method `config' for ScenariosHelper:Module
如何访问我的配置变量?
您可以通过Rails.configuration
访问Rails配置,所以使用:
Rails.configuration.hostname
这应该有效:
url = "https://#{Rails.configuration.hostname}/lti"
我正在使用 rails 5。我在我的 config/environments/development.rb 文件中定义了这个
config.hostname = “myapp.com"
然后我尝试使用
在帮助文件中访问它url = "https://#{config.hostname}/lti"
但这会导致错误,
NameError: undefined local variable or method `config' for ScenariosHelper:Module
如何访问我的配置变量?
您可以通过Rails.configuration
访问Rails配置,所以使用:
Rails.configuration.hostname
这应该有效:
url = "https://#{Rails.configuration.hostname}/lti"