简体   繁体   中英

How to call javascript file in Ruby On Rails

I have two Layouts and each layout have different CSS and Js files. while i use

<%= javascript_include_tag 'application' %>

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?

Thanks.

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' %>

This will include all the javascript files of folder directory.

Look at Asset Pipeline Guide for more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM