Keep your controller specific CSS/JavaScript separated!
Ruby HTML CSS JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
spec
.gitignore
.rspec
.rubocop.yml
.travis.yml
Gemfile
Gemfile.lock
MIT-LICENSE
README.md
Rakefile
rails-controller-assets.gemspec

README.md

RailsControllerAssets

Build Status Code Climate

This gems allows to automatically precompile bundles of assets per controller or controller/action pair.

It's great when you want to keep action or controller specific CSS/JavaScript in a separate file.

Usage

In your Gemfile:

gem 'rails-controller-assets'

Create new bundle files (eg. like application.css) for a PostsController:

In app/assets/stylesheets/posts.css:

.post-title { color: red }

In your application layout add to your stylesheets definition:

<%= stylesheet_link_tag 'application', *controller_stylesheets %>
<%= javascript_include_tag 'application', *controller_javascripts %>

And that's it!

The gem will look for bundle files that match:

  • {controller_name}.{js|css}
  • {controller_name}_{action_name}.{js|css}

Author

Brought to you by Piotr Usewicz.