71

我正在共享一个配置 yml 文件客户端,我还需要在服务器端加载它,我已将它放在 app/assets/javascripts/configuration.yml

我可以在视图中使用 #{asset_path 'configuration.yml'} 来获取路径,但我不能在控制器中使用。我可以使用“#{Rails.root}/app/assets/javascripts/configuration.yml”直接访问,但是在部署文件名时会附加摘要字符串。

如何从控制器获得相同的路径?

4

1 回答 1

117
ActionController::Base.helpers.asset_path("configuration.yml")

将 configuration.yml 放在不同的文件夹中以将 javascript 与非 javascript 文件分开也可能会很好。

于 2011-10-19T20:13:20.683 回答