From be66f7061d6f5d5adbdd84cba4e4758aff9b1077 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sun, 7 May 2023 16:39:02 +0200 Subject: [PATCH] Fix 500 on Discover --- app/controllers/discover_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/discover_controller.rb b/app/controllers/discover_controller.rb index 7f415c78..2e1be8b4 100644 --- a/app/controllers/discover_controller.rb +++ b/app/controllers/discover_controller.rb @@ -13,6 +13,9 @@ class DiscoverController < ApplicationController @popular_questions = Question.where("created_at > ?", Time.now.ago(1.week)).order(:answer_count).reverse_order.limit(top_x).includes(:user) @new_users = User.where("asked_count > 0").order(:id).reverse_order.limit(top_x).includes(:profile) + answer_ids = @popular_answers.map(&:id) + @most_discussed.map(&:id) + @subscribed_answer_ids = Subscription.where(user: current_user, answer_id: answer_ids).pluck(:answer_id) + # .user = the user # .question_count = how many questions did the user ask @users_with_most_questions = Question.select('user_id, COUNT(*) AS question_count').