我report.rb类包含以下代码:实例变量似乎失去其价值
def create
@start_term = ::SchoolTerm.find(1705265)
@end_term = ::SchoolTerm.currently_enrolling
current = 0
total = all_terms.size
@terms = {}
all_terms.each do |t|
@terms[t.id] = Business::Sales::RevenueByWeek::Term.new(t)
Rails.logger.info("#{@terms} is @terms in report#create")
current += 1
self.progress = 100.0 * (Float(current)/Float(total))
end
end
def all_terms
::SchoolTerm.between(@start_term, @end_term) - RevenueGoal.terms_without
end
def each
Rails.logger.info("#{@terms} is @terms in report.each")
all_terms.each do |t|
yield @terms[t.id] if @terms[t.id]
end
end
记录仪线内创建显示,@terms同时通过不同的学期循环具有正确的价值观。但是,每种方法中的记录器行都显示@terms为空。当我尝试加载的报告,我得到这个错误:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
Extracted source (around line #24):
</tr>
</thead>
<% report.each do |term| %>
<tbody class="term_<%= term.id %>">
<tr class="term">
<th><%= term.term %></th>
我已经验证业务::销售:: RevenueByWeek :: Term.new返回正确的数据。任何想法,为什么我得到这个零对象错误?我认为实例变量保留了它们的值,但不知何故,这个变量会丢失。
谢谢。
请显示您如何使用此代码,流程如何。 –