Skip to content

Commit

Permalink
Fix exception
Browse files Browse the repository at this point in the history
  • Loading branch information
nmondollot committed Dec 26, 2024
1 parent af3bc14 commit aad23a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/controllers/circuits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class CircuitsController < ApplicationController
def index
@circuits = Circuit.all.sort_by(&:average_grade)
@circuits = Circuit.all.select { |c| c.problems.any? }.sort_by(&:average_grade)
end

def show
@circuit = Circuit.find(params[:id])
redirect_to circuits_path unless @circuit.problems.any?

@area = @circuit.main_area
end
end
3 changes: 2 additions & 1 deletion app/models/circuit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def name
end

def main_area
problems.order(:circuit_number).first.area
problems.order(:circuit_number).first&.area
end

def bounds
Expand Down Expand Up @@ -53,6 +53,7 @@ def beginner_friendly?

private
def average(array)
return 0 if array.empty?
array.reduce(:+) / array.size.to_f
end
end

0 comments on commit aad23a8

Please sign in to comment.