我正在尝试编写不显眼的 javascript,我认为:
<%= javascript_include_tag "trend" %>
在我的trend.js.erb 中有:
$(document).ready(function() {
<% @testsss.each do |t|%>
$('#<%= "t-"+t.id.to_s %>').click(function(event){
//alert("sometext");
$.ajax({type: "GET", url: "/returngraph?test=<%= t.id.to_s %>", dataType: "html",success:
function(data){ $("#chart").html(data)} });
});
<% end %>
});
但我得到了 NoMethodError ......我做错了什么?@testsss 是一组对象,相同的 @testsss.each 在trend.html.erb 中工作,我称之为 javascript_include_tag “trend”
谢谢你
编辑:
这是实际错误:
NoMethodError in Statisticall#trend
Showing /xxxx/app/views/statisticall/trend.html.erb where line #1 raised:
undefined method `each' for nil:NilClass
(in /xxxx/app/assets/javascripts/trend.js.erb)
Extracted source (around line #1):
1: <%= javascript_include_tag "trend" %>
2: <div id="hhead">
我有控制器统计和动作趋势