we have a rails 5.1.7 application and all is working fine in the dev environment. but in staging environment or when running server using rails s -e staging, we see this error "Sprockets::Rails::Helper::AssetNotFound".
example, The asset "fontawesome-free-5.1.1-web/css/all.min.css" is not present in the asset pipeline
the folder fontawesome-free-5.1.1-web is located under public/styleheets.
I have tried moving the folder to vendor/stylesheets or assets/stylesheets but I see the same error.
below is my environments/staging.rb
AppName::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
config.log_level = :debug
memcached_config = YAML.load_file(Rails.root.join('config/memcached.yml'))
memcached_hosts = memcached_config['defaults']['servers']
config.cache_store = :mem_cache_store, *memcached_hosts
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.eager_load = true
config.assets.js_compressor = Uglifier.new(harmony: true)
config.assets.compile = false
config.assets.raise_runtime_errors = true
config.assets.debug = true
end
Any help on what could be going wrong here would be really great, Thanks.
I'm assuming you're doing this:
Directories in
vendor/assetsandapp/assetsare automatically added to assets paths. These are the paths sprockets is using to find assets:You have
config.assets.compile = false, that means sprockets is done looking around in assets paths and compiling on the fly. It's now expecting precompiled assets inpublic/assets:You have to
bin/rails assets:precompile:Should work now:
https://guides.rubyonrails.org/v5.0/configuring.html#configuring-assets
Update
To handle files in bulk, there are two options. Add a proc that would dynamically match assets for precompilation:
https://github.com/rails/sprockets-rails/blob/v3.4.2/lib/sprockets/railtie.rb#L88
A better option is to use
manifest.js, which is the default in later rails versions:https://github.com/rails/sprockets#directives
Also, when you precompile assets, that means you want load them directly through a url. If you just use
//= requiredirectives, then required files don't need to be precompiled as they are merged into the file that gets precompiled. You just get one bigapplication.cssfile:If you're precompiling locally to test things out, don't forget to
bin/rails assets:clobberafter you're done, you don't want precompiled assets in development.