Dead simple asset dispatching that works with turbolinks. Specify code or styles that only apply to certain controllers and actions.
- Put
gem 'assetdispatch', git: 'http://git.devlinzed.com/assetdispatch'
in your Gemfile. - Put
//= require assetdispatch
in your JavaScript manifest file. - Ensure your
html
tag hasdata-action
anddata-controller
attributes. You can replace%html{ lang: I18n.locale }
with= html_tag(lang: I18n.locale) do
to do this, or add them yourself.
route('application#initialize', function() {
// called when the page loads
});
route('posts#show', function() {
// called when you're on pages#show
});
route('admin#initialize', 'application#edit', function(controller, action) {
// called when you're on any AdminController or edit page
});
html[data-controller=posts][data-action=show] {
/* only affects posts#show */
}