Last Updated: February 25, 2016
·
1.243K
· pjmorse

Gems providing assets must be in Gemfile

For an asset (e.g. a Javascript file) provided by a gem to be available for asset compiling, the gem must be listed in the Gemfile, not a dependency of another gem. Only gems listed in the Gemfile have their asset paths included in Rails::Application.config.assets.paths. Here's a contrived example:

The bestinplace editor has jquery-rails as a dependency. If bestinplace is in the Gemfile, but jquery-rails is not, a line like this

//= require jquery_ujs

...will generate a "file not found" error when the assets:precompile task is run. This is because only gems in the Gemfile have their asset paths added to Sprockets' search path. (Obviously if you're installing bestinplace it's extremely unlikely that you don't already have jquery-rails in your Gemfile. That's why this is a contrived example.)