如何在Ruby On Rails中调用javascript文件 [英] How to call javascript file in Ruby On Rails
本文介绍了如何在Ruby On Rails中调用javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个布局,每个布局都有不同的 CSS 和 Js 文件。我使用时
I have two Layouts and each layout have different CSS and Js files. while i use
<%= javascript_include_tag'应用'%>
然后,它会带来所有的.js文件。
then, it brings all .js files.
有什么可用的方式如下:
Is anything available like following way:
<%= javascript_include_tag 'folder/script1.js' %>
<%= javascript_include_tag 'folder/script2.js' %>
<%= javascript_include_tag 'folder/script3.js' %> ...
有没有办法只包含特定文件夹中的所有脚本?
Is there a way to only include all scripts in an specific folder?
谢谢。
推荐答案
创建一个新文件 application_foo。 js
包含以下内容;
Create a new file application_foo.js
with the following content;
//= require_directory folder
在第二个布局中添加以下行:
Add the following line in your second layout:
<%= javascript_include_tag 'application_foo' %>
这将包括文件夹的所有javascript文件
目录。
看看资产管道指南了解更多信息。
这篇关于如何在Ruby On Rails中调用javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文