产生javascript的Rails资产管道 [英] rails assets pipeline with yielded javascript

查看:80
本文介绍了产生javascript的Rails资产管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我不想在某些视图中将js文件分开,因此我在视图内部使用了一个辅助函数,该js函数将js文件输出到html头中

since I wan't to keep my js files separated for some views, I am making use of a helper function inside the view which yields the js file into the html head

   def javascript(*files)
    content_for(:head) { javascript_include_tag(*files) }
   end

所以我想知道如何利用资产管道和预编译机制来实现这一目标? 最好, 菲尔

So I was wondering how can I achieve this with assets the pipeline and the pre compile mechanism? Best, Phil

推荐答案

HTML头部分中所需的每个JS文件都需要进行预编译.默认情况下,仅对application.js进行预编译,但是您可以在config/application.rb中安排其他文件进行预编译:

Every JS file that is being required in the HTML head section needs to be precompiled. By default only application.js is being precompiled, but you can schedule additional files for precompilation in config/application.rb:

config.assets.precompile += ['admin.js', 'customer_page.js']

如果要将JS文件分组在一起,这些文件可以像application.js一样是清单.

Those files can be manifests, just like application.js, if you want to group the JS-files together.

这篇关于产生javascript的Rails资产管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆