Skip to content

Instantly share code, notes, and snippets.

@alexruzenhack
Last active April 20, 2017 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexruzenhack/bc3c14817751193e8706a4ab8bf22fc9 to your computer and use it in GitHub Desktop.
Save alexruzenhack/bc3c14817751193e8706a4ab8bf22fc9 to your computer and use it in GitHub Desktop.
🍕 add javascript asset per controller on page if the asset exists

Rails assets per controller

Check if asset exists with find_asset before include it.

<!-- Include javascript per-controller - vendor plugins -->
<%= javascript_include_tag params[:controller] 
        if ::Rails.application.assets.find_asset("#{params[:controller]}.js") %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment