开发者

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜