Skip to content

Instantly share code, notes, and snippets.

@riyad
Created May 23, 2012 13:45
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riyad/2775306 to your computer and use it in GitHub Desktop.
Save riyad/2775306 to your computer and use it in GitHub Desktop.
Render Rails assets to string
module ApplicationHelper
# thanks to http://blog.phusion.nl/2011/08/14/rendering-rails-3-1-assets-to-string/
# you may need to change the owner of the tmp/cache/* directories to the web servers user
# e.g. for Debian systems: `chown -R www-data:www-data tmp/cache/*`
def render_asset(asset)
Conferator::Application.assets.find_asset(asset).body.html_safe
end
end
@niyando
Copy link

niyando commented Jun 3, 2016

this doesn't work with assets with erb extension .. for eg.. blabla.js.erb
It does render, but the embedded ruby remains un-executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment