32

I'm getting that error on my production server, and can't figure out why. It happens when running this command:

bundle exec rake assets:precompile RAILS_ENV=production

I'm using Rails 3.1.0.rc6

Cœur
  • 34,719
  • 24
  • 185
  • 251
tybro0103
  • 46,085
  • 33
  • 141
  • 168

5 Answers5

82

This is most likely due your config/application.rb not requiring rails/all (the default), but some custom requires.

To resolve this, add the following to config/application.rb:

require 'sprockets/railtie'
Koraktor
  • 38,541
  • 9
  • 69
  • 98
4

I know this is an old post but I thought it might help someone (probably my future self) if I added this to the answers.

add to Capfile (or deploy.rb)

load 'deploy/assets'

add this to application.rb

require 'sprockets/railtie'
engineerDave
  • 3,841
  • 23
  • 28
4

I was running this command -- out of sheer habit -- in the root of an API-only app, which, of course, has no assets.

Niek
  • 1,278
  • 15
  • 23
3

I think that it might be because you aren't requiring the asset gems in production. By default rails expects that you are pre-compiling your assets in production. Change this in config/application.rb:

Comment out this line:

Bundler.require *Rails.groups(:assets => %w(development test))

And uncomment this line:

Bundler.require(:default, :assets, Rails.env)

  • I'm not a mongoid user like the currently accepted answer mentions in the comments. In my case I had a seperate environment just to precompile assets and the error went away once I added the new environment to the list mentioned in this answer. – ErJab Aug 08 '13 at 04:31
  • I had an extremely old app (2008), that doesn't even have sprockets, so this is the answer I needed. Cap defaults to expecting to precompile the asset pipeline, but since there is no asset pipeline it fails. – Josh from Qaribou Oct 20 '16 at 13:05
1

That's strange. You could always try adding

load "sprockets/assets.rake"

to your Rakefile. It should be included by the actionpack railtie.

My Rakefile contains:

require File.expand_path('../config/application', __FILE__)
Qnm::Application.load_tasks
qnm
  • 521
  • 3
  • 14