After gem update: test fail with Asset was not declared to be precompiled in production
Long Answer + Explanation
I think the correct fix is to add the file to the precompiled assets, as recommended by the error message. Maybe that isn't fixing the issue for you because you've got an erb file that needs to be rendered at run time. I imagine if the file was a static json file then you would not still experience the issue after adding it to the precompiled assets.
When you use the image_path
helper, Sprockets is assuming that you've got a static asset. The fact that your app didn't raise errors before sprockets-rails
3.0 is somewhat surprising. This new version is doing a better job, apparently, at enforcing the standards. (it also looks like there are other problems with 3.0 that might be updated shortly)
If you need to have erb inside the manifest, then it would be best practice to use a route path helper rather than image_path
or asset_path
to get the url. This would require you to add a manifest route to your config/routes.rb
file and render the json file through a controller action. The view file would be your .erb
manifest.
Short Answer
This started happening to me after doing a bundler update
that changed my sprockets-rails
version from 2.3.3 to 3.0.0. A simple fix is to revert sprockets-rails
back to version 2.3.3 in your Gemfile and running bundle install
again:
gem 'sprockets-rails', '2.3.3'
As an aside: I was experiencing this issue in development environment and was able to fix it there by running rake assets:precompile
. Unfortunately, it didn't get my tests passing.
Sprocket Error - Asset was not declared to be precompiled in production
%w
creates an array of words using whitespace to separate each value
%w( home.css, home.coffe )
returns
["home.css,", "home.coffe"]
change code to
Rails.application.config.assets.precompile += %w( home.css home.coffe )
Assets say not precompiled when they are precompiled
I have been wrestling with the problem myself, although with config.assets.compile = false
set, as I suspect the example above was with the flag set to true
.
Cannot configure assets via pipeline on local production rails 3.1.3 server
My observations came down to it being a Sprockets 2.0.3 bug, as UberNeet suggested towards. The workaround was to either remove the period from the asset name, or include it as part of a manifest, rather than link to it directly.
The bug report for this is here: https://github.com/rails/rails/issues/3398
Looking at your issue above, and tallying it with my experience from the last two days, I suspect there is an associated issue with asset naming when config.assets.compile = true
is set. This issue probably stems from the asset naming - your manifest has the jquery.autocomplete library percompiled as:
jquery-5550a245a55b28927b5552cac182e612.autocomplete.js
But when you precompile these assets via rake using rake assets:precompile
, I believe they are actually compiled to:
jquery.autocomplete-5550a245a55b28927b5552cac182e612.js
It is probably this discrepancy that is causing the issue you mentioned. Might be worth raising another github issue for this too, although the workarounds are listed above, and I understand that Rails 3.2 will be using Sprockets 2.1.0, which may contain the fix for this issue already.
Sprockets Rails Helper Asset Not Precompiled even though declared in config/initializers/assets.rb
Add the extension to Rails.application.config.assets.precompile += %w( quickbed_logo.png )
because Rails cannot guess it.
Rails: Sprockets::Rails::Helper::AssetNotPrecompiled in development
Please check the file
config/environments/development.rb
config.assets.debug = true (if TRUE change to FALSE)
Problems with asset precompile after updating to Rails 4
The :assets group is not loaded in the production environment by default, you can change this in your config/application.rb (https://github.com/Wolox/mgmt/blob/master/config/application.rb#L7 in your repo)
The advised practice is to compile your assets in development and then push the /public/assets directory to production once you're satisfied nothing breaks.
Use this line instead, and you should be fine:
RAILS_ENV=development bundle exec rake assets:precompile
Rails Assets Not Compiled in Production
Adding require landing_page
to application.css does not cause landing_page to be precompiled. It means that when application.css is precompiled, the contents of landing_page.css will be included in the output.
If you are going to load them individually, ie
<%= stylesheet_link_tag params[:controller] %>
Then you will need to add them all to the list of things to precompile. You can use wildcards in that list, so if these controller specific stylesheets were all in stylesheets/controllers then you could do
config.assets.precompile += ["controllers/*.css"]
Typically though people tend not to do this. While for ease of development things are often split up on a per controller basis, all of these are then required from application.css. Application.css is then the only stylesheet you call stylesheet_link_tag
on
Related Topics
How to Get Activerecord Associations via Reflection
How to Generate a Random Number Between a and B in Ruby
Capybara: Select an Option by Value Not Text
Rails: Good Rspec2 Example Usage? (Also: Cucumber, Pickle, Capybara)
Ruby Method Calls Declared in Class Body
Extract Links (Urls), with Nokogiri in Ruby, from a Href HTML Tags
Rails Authentication Across Apps/Servers
Find Out If an Ip Is Within a Range of Ips
Ruby: Most Concise Way to Use an Env Variable If It Exists, Otherwise Use Default Value
Attr_Accessor on Class Variables
Installing the Postgresql Gem with 'Gem Pq' Fails with Error: Failed to Build Gem Native Extension
Purpose of & (Ampersand) in Ruby for Procs and Calling Methods