Sydney
Sydney

Reputation: 1439

Rails: Sprockets::Rails::Helper::AssetNotPrecompiled in development

I am relatively new to Rails and I am trying to use the asset pipeline, SCSS, in the development environment. However, after I created the controller, the view, and the css.scss file, I encounter the following error:

Sprockets::Rails::Helper::AssetNotPrecompiled

Here is the error message:

Asset was not declared to be precompiled in production. Add Rails.application.config.assets.precompile += %w( public.css ) to config/initializers/assets.rb and restart your server

I read that in development, the assets get compiled on the fly and there is no need to pre-compile. Why is there a pre-compile error? Did Rails think that I am in production instead of development?

Edited on 1 March 2016 ------

I just realized that adding files onto the config/initializers/assets.rb works. But is this the right way to do it? I have to add all the css/js/jpg files manually in the assets.rb for it to work. I felt that this somehow violate the DRY principle.

Upvotes: 59

Views: 45239

Answers (12)

bingoding
bingoding

Reputation: 51

Try rake tmp:clear

References - https://github.com/rails/sprockets-rails/issues/458

Upvotes: 5

Ameer Hamza
Ameer Hamza

Reputation: 331

//= link_directory ../javascripts .js

Adding this to app/assets/config/manifest.js
Worked for me (working on rails 6)

Upvotes: 31

kushagra gupta
kushagra gupta

Reputation: 21

Add this to app/assets/config/manifest.js

//= link_directory ../javascripts .js

Upvotes: 0

iCyborg
iCyborg

Reputation: 4728

Do not forget to restart the app too if you pulled new code.

Upvotes: 0

RawKnee
RawKnee

Reputation: 323

Just adding here in case it might help someone.

I had a specific JS files I wanted only in a specific ActiveAdmin page and it was under /app/assets/javascripts/admin/orders.

Initially, none of the solutions worked for me beside adding this to config/environments/development.rb:

config.assets.check_precompiled_asset = false

A coworker mentioned that this change is a bit fishy and I tend to agree. Like what are the implications this will have on our development? Will we see errors related to precompilation of assets only in staging / prod from now?

Since I had subdirectories including JS files under my /app/assets/javascripts folder, I tried changing

//= link_directory ../javascripts .js

to

//= link_tree ../javascripts

And it solved it for me. Without the config.assets.check_precompiled_asset = false in the development.rb file.

Upvotes: 1

gersanco
gersanco

Reputation: 603

I had the same problem and fixed it by deleting all the cache files inside the tmp folder

rm -rf tmp/cache/assets

Upvotes: 58

Dorian
Dorian

Reputation: 9185

I needed to declare my assets in my manifest:

//= link_directory ../stylesheets .css

in app/assets/config/manifest.js

Upvotes: 2

Max Paprikas
Max Paprikas

Reputation: 619

For those who came here after upgrading from rails 4 to 5-6 - checkout manifest.js

app/assets/config/manifest.js

If there is no link to js - just add one:

//= link_directory ../javascripts .js

Upvotes: 20

muthupandi
muthupandi

Reputation: 63

you can initialize this scss file for the following line of code

Rails.application.config.assets.precompile += %w( applicationname.css )

Upvotes: 6

eben.english
eben.english

Reputation: 1685

Neither of these worked for me (rails-5.0.7, sprockets-3.7.2, sprockets-rails-3.2.1):

config.assets.debug = false
config.assets.unknown_asset_fallback = true

But this did:

config.assets.check_precompiled_asset = false

Upvotes: 151

Arctodus
Arctodus

Reputation: 5847

Changing assets.debug did not work for me in Rails v5.1.5. I had to use this option: config.assets.unknown_asset_fallback = true

Upvotes: 9

aldrien.h
aldrien.h

Reputation: 3635

Please check the file

config/environments/development.rb

config.assets.debug = true (if TRUE change to FALSE)

Upvotes: 9

Related Questions