How to use javascript_include_tag to get all scripts in a folder

前端 未结 4 729
走了就别回头了
走了就别回头了 2021-02-08 18:13

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

I\'m tryi

4条回答
  •  长情又很酷
    2021-02-08 19:05

    The following (unoptimized) code should work in rails 3.0 or above

    <%= javascript_include_tag Dir[Rails.root.join("public/javascripts/views/**/*.js")].map { |s| s.sub(Rails.root.join("public/javascripts/").to_s, "") } %>
    

提交回复
热议问题