Include Assets Only If They Exist

前端 未结 5 1730
情歌与酒
情歌与酒 2021-02-19 07:41

In our current rails app, we are following certain patterns for including assets such as scripts and stylesheets.

For instance, one such pattern is (code inside the layo

5条回答
  •  借酒劲吻你
    2021-02-19 08:20

    Finally figured this one out. Asset existence can be checked as follows:

    YourApp::Application.assets.find_asset("#{asset}.css").nil?
    

    The answer would then be:

    = stylesheet_link_tag controller.controller_name if YourApp::Application.assets.find_asset("#{controller.controller_name}.css")
    

提交回复
热议问题