There is a code
j = 0 10.times do |i| if @days[k].mday == reservs_room[j][0].mday then colspan = reservs_room[j][1]*2 j += 1 else colspan = 1 end end Screams and swears
undefined method `[] 'for nil: NilClass
Change to
10.times do |i| if @days[k].mday == reservs_room[0][0].mday then colspan = reservs_room[0][1]*2 else colspan = 1 end end and all is well, what is the matter?
Full example:
@days = Array.new(daysCount) i = 0; (-2..daysCount - 3).map {|n| @days[i] = Time.now + n.day; i += 1;} @reserv_cols = Array.new(@rooms.length) @rooms.each_index do |row_index| @reserv_cols[row_index] = [] k = 0 reservs_room = [[(Time.now), 3], [(Time.now+5.day), 5]] sum_day_reserv = 8 j = 0 num = 2*daysCount-1-sum_day_reserv*2 num.times do |i| if @days[k].mday == reservs_room[j][0].mday then colspan = reservs_room[j][1]*2 j += 1 else colspan = 1 end @reserv_cols[row_index].push([@days[k], colspan]) if i.odd? then k += 1 end end end
reservs_roomis less than 10 elements in thereservs_roomarray. - MAXOPKAblank?present?any?. If you want your code to be readable and understandable - it is better to use the style guides . In this mess it was very difficult to make out something. - anoamany?never checked an array for emptiness. - Nakilon