2015-05-13 11:39:04 -07:00
|
|
|
class DiscoverController < ApplicationController
|
2015-05-13 11:56:51 -07:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
|
|
|
|
def index
|
2015-05-13 12:58:00 -07:00
|
|
|
top_x = 10 # only display the top X items
|
2015-05-13 11:56:51 -07:00
|
|
|
|
2015-05-13 12:58:00 -07:00
|
|
|
@popular_answers = Answer.where("created_at > ?", Time.now.ago(1.week)).order(:smile_count).reverse_order.limit(top_x)
|
|
|
|
@popular_questions = Question.where("created_at > ?", Time.now.ago(1.week)).order(:answer_count).reverse_order.limit(top_x)
|
|
|
|
@new_users = User.order(:id).reverse_order.limit(top_x)
|
|
|
|
|
|
|
|
# .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(author_is_anonymous: false).
|
|
|
|
group(:user_id).
|
|
|
|
order('question_count').
|
|
|
|
reverse_order.limit(10)
|
2015-05-13 11:56:51 -07:00
|
|
|
end
|
2015-05-13 11:39:04 -07:00
|
|
|
end
|