1

I have read that if you want to include a javascript file specific to your view you can use content_for and yield functions of ruby. Following is sample code to do it. I want to know what is the path where it will look for forms.js.

<% content_for :javascript_includes do %>
  <%= javascript_include_tag "forms.js" %>
<% end %>
4

1 回答 1

0

TL;DR 使用content_for对资产的查找路径没有影响。

Rails 将查看多个位置,就像所有资产一样。万一forms.js它会寻找

  1. app/assets/javascripts/forms.js
  2. lib/assets/javascripts/forms.js
  3. vendor/assets/javascripts/forms.js

(如果在这些位置之一找不到,它将继续查找所有必需的 gem,这些 gem 提供了一个 Rails 引擎。在这些 gem 中,它将再次查看上面给出的位置。)

于 2014-08-16T12:21:53.617 回答