Fix NameError in Discover

This commit is contained in:
Karina Kwiatek 2023-12-09 14:05:42 +01:00
parent b421f1d149
commit df1832dc5a
1 changed files with 6 additions and 5 deletions

View File

@ -6,17 +6,18 @@ class DiscoverController < ApplicationController
return redirect_to root_path
end
top_x = 10 # only display the top X items
top_x = 10 # only display the top X items
week_ago = Time.now.utc.ago(1.week)
@popular_answers = Answer.for_user(current_user).where("created_at > ?", Time.now.utc.ago(1.week)).order(:smile_count).reverse_order.limit(top_x).includes(:question, :user, :comments)
@most_discussed = Answer.for_user(current_user).where("created_at > ?", Time.now.utc.ago(1.week)).order(:comment_count).reverse_order.limit(top_x).includes(:question, :user, :comments)
@popular_questions = Question.where("created_at > ?", Time.now.ago(1.week)).order(:answer_count).reverse_order.limit(top_x).includes(:user)
@popular_answers = Answer.for_user(current_user).where("created_at > ?", week_ago).order(:smile_count).reverse_order.limit(top_x).includes(:question, :user, :comments)
@most_discussed = Answer.for_user(current_user).where("created_at > ?", week_ago).order(:comment_count).reverse_order.limit(top_x).includes(:question, :user, :comments)
@popular_questions = Question.where("created_at > ?", week_ago).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)
# .user = the user
# .question_count = how many questions did the user ask
@users_with_most_questions = Question.select('user_id, COUNT(*) AS question_count').
where("created_at > ?", Time.now.ago(1.week)).
where("created_at > ?", week_ago).
where(author_is_anonymous: false).
group(:user_id).
order('question_count').