`undefined method `find_asset' for nil:NilClass` `undefined method `find_asset' for nil:NilClass` ruby ruby

`undefined method `find_asset' for nil:NilClass`


To get it work for development and production environment don't use

Rails.application.assets.find_asset(logical_file_path).to_s

for sprockets-rails version > 3.0.0 but use this (requires gem compass-rails):

CompassRails.sprockets.find_asset(logical_file_path).to_s

If you don't use gem compass-rails you can get the asset with:

(Rails.application.assets || ::Sprockets::Railtie.build_environment(Rails.application)).find_asset(logical_file_path).to_s


A simple Google search, revealed that this error was reported in the official wicked_pdf repo in December.

Setting assets.compile = true as recommended in the issue would fix it. This change should not be necessary with sprocket-rails != 3.0.0