Access Asset Path from Rails Controller

Ruby on-RailsRuby on-Rails-3.1Sprockets

Ruby on-Rails Problem Overview


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?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarcel M.View Question on Stackoverflow
Solution 1 - Ruby on-RailsArtem KalinchukView Answer on Stackoverflow