Ruby on Rails中的资产管道使用Javascript

时间:2015-08-13 12:18:32

标签: javascript ruby-on-rails ruby ruby-on-rails-3

我在使用Asset Pipeline时遇到了麻烦。虽然我读了一篇优秀的导游here,但我还是遇到了麻烦。

我正在尝试使用javascript解决方案来“动态”添加表单元素[http://jyrkis-blogs.blogspot.com/2014/06/adding-fields-on-fly-with-ruby-on-rails.html#code4Div

当我将javascript放入页面底部的<script>标记时,一切都按预期工作。 如果我只是将脚本复制并粘贴到application.js中,代码也可以正常工作。 但是,当我尝试将代码移动到app/assets/javascripts/people.js时,我的网站会引发参考错误。

这与题为'Ruby on Rails 3.1 RC1 Javascript资产管道问题'的问题类似的问题(链接的代表不够),但我只有一个脚本,所以按字母顺序排列的解决方案没有帮助。将文件移动到vendor / assets / javascript也没有帮助。

Application.js目前看起来像:

This is a manifest file that'll be compiled into application.js, which will include all the files
listed below.

Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.

It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
compiled file.

Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
about supported directives.

= require people.js
= require_tree .

0 个答案:

没有答案