我正在为网站https://looky.co实施网站导览功能,我希望仅在site_tour.js
设置为true时发送show_site_tour
文件。 (show_site_tour
是数据库列)。
我在application.html.haml(布局文件)中设置了它。问题在于heroku运行资产管道的方式。
目录结构
\ app
\ assets
\ javascripts
\ guiders
site_tour.js
基本上问题是,当我尝试仅在数据库列等于true的情况下包含该文件夹时,heroku会给出“资产未预编译”错误。
在我的application.html.haml
中%head
= javascript_include_tag 'application'
- if current_user.show_site_tour == true
= javascript_include_tag 'guiders/site_tour'
那么如何使用heroku管道来完成这项工作呢? 基本上主要问题是,如何在heroku上有多个javascript文件?
答案 0 :(得分:2)
基本上,您需要告诉资产管道将site_tour
文件分开。
config.assets.precompile += %w( guiders/site_tour )
此设置生效后,您应该最终获得两个JavaScript文件,application.js
和site_tour.js
。
您可以使用rake
预编译资产来本地测试。
bundle exec rake assets:precompile
这将向您展示输出如何在Heroku上结束。
值得注意的是Heroku requires that you have the following setting set to false。
config.assets.initialize_on_precompile = false