add Most Comments and Most Answered to Discover

This commit is contained in:
pixeldesu 2015-05-18 00:57:47 +02:00
parent 6b08e6fed5
commit 4400779d00
5 changed files with 29 additions and 3 deletions

View File

@ -5,6 +5,7 @@ class DiscoverController < ApplicationController
top_x = 10 # only display the top X items
@popular_answers = Answer.where("created_at > ?", Time.now.ago(1.week)).order(:smile_count).reverse_order.limit(top_x)
@most_discussed = Answer.where("created_at > ?", Time.now.ago(1.week)).order(:comment_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.where("asked_count > 0").order(:id).reverse_order.limit(top_x)
@ -15,6 +16,14 @@ class DiscoverController < ApplicationController
where(author_is_anonymous: false).
group(:user_id).
order('question_count').
reverse_order.limit(10)
reverse_order.limit(top_x)
# .user = the user
# .answer_count = how many questions did the user answer
@users_with_most_answers = Answer.select('user_id, COUNT(*) AS answer_count').
where("created_at > ?", Time.now.ago(1.week)).
group(:user_id).
order('answer_count').
reverse_order.limit(top_x)
end
end

View File

@ -0,0 +1,3 @@
.tab-pane.fade{role: "tabpanel", id: "comments"}
- comments.each do |a|
= render 'shared/answerbox', a: a

View File

@ -0,0 +1,3 @@
.tab-pane.fade{role: "tabpanel", id: "answered"}
- answered.each do |user|
= render 'discover/userbox', u: user.user, type: "most", a: user.answer_count

View File

@ -18,6 +18,9 @@
registered
= time_ago_in_words(u.created_at)
ago
- elsif type == "most"
answered
= pluralize(a, "question")
- else
asked
= pluralize(q, "question")

View File

@ -9,7 +9,7 @@
= APP_CONFIG['site_name']
.container
.row
.col-md-8.col-sm-6
.col-md-7.col-sm-6
%h2 Popular Content
%p Answers with most smiles and most answered questions
%div{role: "tabpanel"}
@ -20,10 +20,14 @@
%li{role: "presentation"}
%a{href: "#questions", role: "tab", aria: {controls: "questions"}, data: {toggle: "tab"}}
Questions
%li{role: "presentation"}
%a{href: "#comments", role: "tab", aria: {controls: "comments"}, data: {toggle: "tab"}}
Most Comments
.tab-content.discover
= render 'discover/tab_answers', answers: @popular_answers
= render 'discover/tab_questions', questions: @popular_questions
.col-md-4.col-sm-6
= render 'discover/tab_discussed', comments: @most_discussed
.col-md-5.col-sm-6
%h2 People
%p Newcomers and people who asked the most questions
%div{role: "tabpanel"}
@ -34,7 +38,11 @@
%li{role: "presentation"}
%a{href: "#asked", role: "tab", aria: {controls: "asked"}, data: {toggle: "tab"}}
Most Asked Questions
%li{role: "presentation"}
%a{href: "#answered", role: "tab", aria: {controls: "answered"}, data: {toggle: "tab"}}
Most Answers
.tab-content.discover
= render 'discover/tab_new', new: @new_users
= render 'discover/tab_asked', asked: @users_with_most_questions
= render 'discover/tab_most', answered: @users_with_most_answers
= render 'shared/links'