如何使用 javascript_include_tag 获取文件夹中的所有脚本 [英] How to use javascript_include_tag to get all scripts in a folder

查看:38
本文介绍了如何使用 javascript_include_tag 获取文件夹中的所有脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 javascript_include_tag 使用递归获取所有与视图相关的脚本,该脚本放置在 public/javascripts/views 中.

I'd like to use javascript_include_tag to grab all view related scripts using recursion, which a placed in public/javascripts/views.

我正在尝试 javascript_include_tag "/views", :recursive =>正确,但未能添加任何脚本.

I'm trying javascript_include_tag "/views", :recursive => true, but failed to add any script.

问候,阿列克谢·扎哈罗夫

Regards, Alexey Zakharov

推荐答案

根据 API 文档 of javascript_include_tag:

为提供的每个源返回一个 html 脚本标记.

Returns an html script tag for each of the sources provided.

您可以传递存在于 public/javascripts 目录中的 javascript 文件的文件名(.js 扩展名是可选的)以包含在当前页面中,或者您可以传递相对于文档根目录的完整路径.

You can pass in the filename (.js extension is optional) of javascript files that exist in your public/javascripts directory for inclusion into the current page or you can pass the full path relative to your document root.

您不能递归地包含目录中的所有文件.但是,你总是可以写下一行:

You cannot recursively include all files in your directory. However, you always can write something like the next line:

javascript_include_tag *Dir[Rails.root.join("public/javascripts/views/**/*.js")]

这篇关于如何使用 javascript_include_tag 获取文件夹中的所有脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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