← Home

How to use the Bundled assets plugin with Rails' built-in tag helpers

As Nick explains all you have to do to get this working is: use a slightly different route in your routes.rb than I've told you to do in my original article. Nick changed the route to:

map.connect ":asset_dir/:names.:ext",
            :controller => "assets_bundle",
            :action => "fetch",
            :asset_dir => /(stylesheets|javascripts)/,
            :ext => /(css|js)/,
            :names => /[^.]*/

Obviously this routes a request to an URL like /stylesheets/main,content,forms.css to the AssetsBundleController#fetch action ... while it preserves the stylesheets and javascripts directories - and that's where the built-in Rails helpers point by default.

This way, you now can use these neat, little helpers like so:

<%= stylesheet_link_tag 'main,content,forms' %>
<%= javascript_include_tag 'common,forms' %>

... without bothering about any further details like HTML attributes that might be necessary here (and that I personally have to look up every time).

So, that's pretty cool. Thanks Nick! :-)


The same thing, but using Liquid template tags, would be:


Nice, too. Eh?