Skip to content

Commit 6d6c523

Browse files
author
Christopher Talib
authored
Merge pull request #273 from tosdr/fix-empty-services-home-page
scope on services so only services with points show up on home page
2 parents f3dd45b + 2aa983f commit 6d6c523

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

app/controllers/pages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def home
33
if params[:query]
44
@services = Service.where('name ILIKE ? or grade ILIKE ?', "%#{params[:query]}%", "%#{params[:query]}%")
55
else
6-
@services = Service.all
6+
@services = Service.with_points
77
end
88
end
99
end

app/models/service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class Service < ApplicationRecord
66
validates :name, uniqueness: true
77
validates :url, presence: true
88

9+
scope :with_points, -> { joins(:points).where.not(points: []).distinct }
10+
911
def points_by_topic(query)
1012
points.joins(:topic).where("topics.title ILIKE ?", "%#{query}%")
1113
end

0 commit comments

Comments
 (0)