rails double .each error
@sections.each do |section|
section.points.each do |point|
if point.distance_corrected.blank?
@total_distance = total_distance + point.distance
end
end
end
and then I try outputting <%= @total_distance %>
in my view, I get a
NameError in PointsController#calculate
undefined local variable or method `total_distance' for #<PointsController:0x000001030698f8>
error.
I'm not sur开发者_StackOverflow社区e what's wrong here, but I kind of think it's something about that double loop of mine. Can anybody help with this?
The line
@total_distance = total_distance + point.distance
should probably be
@total_distance = @total_distance + point.distance
(unless you have a method or local variable "total_distance" defined somewhere in your controller).
精彩评论