Put Rails assets in the right place

There are three directories where your assets live in Ruby on Rails codebase:

  • app/assets
  • lib/assets
  • vendor/assets

Each of them have a distinct use case:

  • app/assets is for your application code and nothing else. jQuery, bootstrap.css or anything else that someone else wrote does not belong here.
  • lib/assets is for reusable code in your application. This is generic code that you've extracted out of your application code that you're responsible for maintaining.
  • vendor/assets is for imported library code. This is jQuery, underscore, bootstrap and friends.

One of the nice things about the Ruby on Rails framework is the idea of a place for everything and everything in its place. By sticking to Rails conventions, you make it easier for new developers (or yourself a few months from now) to reason about the codebase. A surprisingly large number of codebases completely forego this benefit of Rails by ignoring the conventions.

Another bugbear of mine: there's no point in committing minified vendor code. The Rails asset pipeline will minify your code in production anyway (minifying it twice won't make it "extra" small). The benefit of keeping the full source in your repo is being able to debug it by reading the code.