How to call javascript file in Ruby On Rails

ⅰ亾dé卋堺 提交于 2019-12-23 05:08:13

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/16621844/how-to-call-javascript-file-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!