tybro0103
tybro0103

Reputation: 49743

How to build task 'assets:precompile'

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

Upvotes: 34

Views: 24187

Answers (6)

wandji
wandji

Reputation: 51

This worked for me.
Add require "sprockets/railtie" in applications.rb.
And create an empty manifest file app/assets/config/manifest.js

Upvotes: 0

Niek
Niek

Reputation: 1607

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

Upvotes: 8

engineerDave
engineerDave

Reputation: 3935

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'

Upvotes: 5

Koraktor
Koraktor

Reputation: 42943

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'

Upvotes: 87

Daniel Hoey
Daniel Hoey

Reputation: 31

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)

Upvotes: 3

qnm
qnm

Reputation: 521

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

Upvotes: 1

Related Questions