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?

share|improve this question
up vote 88 down vote accepted
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.

share|improve this answer
1  
Thank you! I didn't need to use /assets/. I can just call ActionController::Base.helpers.asset_path("configuration.yml‌​") I also thought about putting the yml file on another folder, tried adding it directly to the app/assets folder, but I couldn't access it. Thanks for the suggestion anyway. – Marcel M. Oct 19 '11 at 20:42
1  
@MarcelM. you need to add other folder to the search path in application.rb. Like so config.assets.paths << Rails.root.join("app", "assets", "yml") – Paulo Casaretto Jan 25 '13 at 12:04
    
This is deprecated in Rails 4. – Agis Jun 29 '15 at 8:11
2  
@Agis — perhaps include the new recommended solution. – Mike Jul 27 '16 at 18:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.