我正在共享一个配置 yml 文件客户端,我还需要在服务器端加载它,我已将其放置在 app/assets/javascripts/configuration.yml 中
我可以在 View 内使用 #{asset_path 'configuration.yml'} 来获取路径,但不能在 Controller 内使用。我可以使用“#{Rails.root}/app/assets/javascripts/configuration.yml”直接访问,但在部署文件名时会附加摘要字符串。
如何从 Controller 获得相同的路径?
最佳答案
ActionController::Base.helpers.asset_path("configuration.yml")
也可以将configuration.yml放在不同的文件夹中,以将javascript与非javascript文件分开。
关于ruby-on-rails - 从 Rails Controller 访问 Assets 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7827078/