`undefined method `find_asset' for nil:NilClass`

对着背影说爱祢 提交于 2019-12-22 04:50:27

问题


I am using 'rails', '4.2.5' and wicked_pdf gem for generating and downloading PDF, but on Heroku, it's not including css using wicked_pdf_stylesheet_link_tag tag.

Heroku error log:

ActionView::Template::Error (undefined method 'find_asset' for nil:NilClass) 

Did I miss any configuration here?


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/35251759/undefined-method-find-asset-for-nilnilclass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!