Access Asset Path from Rails Controller

亡梦爱人 提交于 2019-12-17 08:35:11

问题


I'm sharing a configuration yml file client side, that I need to also load on the server side, I've placed it inside app/assets/javascripts/configuration.yml

I can use #{asset_path 'configuration.yml'} inside a view to get the path, but I can't inside a controller. I could access directly using "#{Rails.root}/app/assets/javascripts/configuration.yml" but when deploying the filename gets the digest string appended.

How can I get the same path from a controller?


回答1:


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

Might also be good to put configuration.yml in a different folder to separate javascript from non-javascript files.



来源:https://stackoverflow.com/questions/7827078/access-asset-path-from-rails-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!