added question#show thing and more...
This commit is contained in:
parent
a9f5ddab65
commit
7de522a82f
12
Rakefile
12
Rakefile
|
@ -27,6 +27,18 @@ namespace :justask do
|
||||||
end
|
end
|
||||||
progress.increment
|
progress.increment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
total = Question.count
|
||||||
|
progress = ProgressBar.create title: 'Processing questions', format: format, starting_at: 0, total: total
|
||||||
|
Question.all.each do |question|
|
||||||
|
begin
|
||||||
|
answers = Answer.where(question: question).count
|
||||||
|
question.answer_count = answers
|
||||||
|
question.save!
|
||||||
|
end
|
||||||
|
progress.increment
|
||||||
|
end
|
||||||
|
|
||||||
total = Answer.count
|
total = Answer.count
|
||||||
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
|
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
|
||||||
Answer.all.each do |answer|
|
Answer.all.each do |answer|
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class QuestionController < ApplicationController
|
||||||
|
def show
|
||||||
|
@question = Question.find(params[:id])
|
||||||
|
@answers = @question.answers.reverse_order
|
||||||
|
end
|
||||||
|
end
|
|
@ -7,15 +7,17 @@ class Inbox < ActiveRecord::Base
|
||||||
user: user,
|
user: user,
|
||||||
question: self.question)
|
question: self.question)
|
||||||
user.increment! :answered_count
|
user.increment! :answered_count
|
||||||
|
self.question.increment! :answer_count
|
||||||
self.destroy
|
self.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove
|
def remove
|
||||||
|
self.question.decrement! :answer_count
|
||||||
unless self.question.user.nil?
|
unless self.question.user.nil?
|
||||||
self.question.user.decrement! :asked_count if self.question.answers.count == 1
|
self.question.user.decrement! :asked_count if self.question.answer_count == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
self.question.destroy if self.question.answers.count == 1
|
self.question.destroy if self.question.answer_count == 1
|
||||||
self.destroy
|
self.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,11 @@
|
||||||
asked
|
asked
|
||||||
= time_ago_in_words(i.question.created_at)
|
= time_ago_in_words(i.question.created_at)
|
||||||
ago
|
ago
|
||||||
|
- unless a.question.author_is_anonymous
|
||||||
|
- if a.question.answer_count > 0
|
||||||
|
·
|
||||||
|
%a{href: show_user_question_path(i.question.user.screen_name, i.question.id)}
|
||||||
|
#{a.question.answer_count} response(s)
|
||||||
%p.answerbox-question-text= i.question.content
|
%p.answerbox-question-text= i.question.content
|
||||||
.panel-body
|
.panel-body
|
||||||
%textarea.form-control{name: 'ib-answer', 'data-id' => i.id}
|
%textarea.form-control{name: 'ib-answer', 'data-id' => i.id}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
.container.j2-page
|
||||||
|
/ TODO: make this pretty (it's currently C-c'd straight from shared/_answerbox)
|
||||||
|
.panel-heading
|
||||||
|
.media
|
||||||
|
- unless @question.author_is_anonymous
|
||||||
|
%a.pull-left{href: show_user_profile_path(@question.user.screen_name)}
|
||||||
|
%img.img-rounded.img-answerbox{src: gravatar_url(@question.user)}
|
||||||
|
.media-body
|
||||||
|
%h6.text-muted.media-heading.answerbox-question-user
|
||||||
|
= user_screen_name @question.user, @question.author_is_anonymous
|
||||||
|
asked
|
||||||
|
= time_ago_in_words(@question.created_at)
|
||||||
|
ago
|
||||||
|
%p.answerbox-question-text= @question.content
|
||||||
|
|
||||||
|
- @answers.each do |a|
|
||||||
|
= render 'shared/answerbox', a: a, show_question: false
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
.panel.panel-default.answer-box{'data-id' => a.id}
|
.panel.panel-default.answer-box{'data-id' => a.id}
|
||||||
.panel-heading
|
- if @question.nil?
|
||||||
.media
|
.panel-heading
|
||||||
- unless a.question.author_is_anonymous
|
.media
|
||||||
%a.pull-left{href: show_user_profile_path(a.question.user.screen_name)}
|
- unless a.question.author_is_anonymous
|
||||||
%img.img-rounded.img-answerbox{src: gravatar_url(a.question.user)}
|
%a.pull-left{href: show_user_profile_path(a.question.user.screen_name)}
|
||||||
.media-body
|
%img.img-rounded.img-answerbox{src: gravatar_url(a.question.user)}
|
||||||
%h6.text-muted.media-heading.answerbox-question-user
|
.media-body
|
||||||
= user_screen_name a.question.user, a.question.author_is_anonymous
|
%h6.text-muted.media-heading.answerbox-question-user
|
||||||
asked
|
= user_screen_name a.question.user, a.question.author_is_anonymous
|
||||||
%a{href: show_user_answer_path(a.user.screen_name, a.id)}
|
asked
|
||||||
= time_ago_in_words(a.question.created_at)
|
%a{href: show_user_answer_path(a.user.screen_name, a.id)}
|
||||||
ago
|
= time_ago_in_words(a.question.created_at)
|
||||||
%p.answerbox-question-text= a.question.content
|
ago
|
||||||
|
- unless a.question.author_is_anonymous
|
||||||
|
- if a.question.answer_count > 1
|
||||||
|
·
|
||||||
|
%a{href: show_user_question_path(a.question.user.screen_name, a.question.id)}
|
||||||
|
#{a.question.answer_count} answers
|
||||||
|
%p.answerbox-question-text
|
||||||
|
= a.question.content
|
||||||
.panel-body
|
.panel-body
|
||||||
%p= a.content
|
%p= a.content
|
||||||
- if @user.nil?
|
- if @user.nil?
|
||||||
|
|
|
@ -41,6 +41,8 @@ Rails.application.routes.draw do
|
||||||
match '/user/:username(/p/:page)', to: 'user#show', via: 'get', defaults: {page: 1}
|
match '/user/:username(/p/:page)', to: 'user#show', via: 'get', defaults: {page: 1}
|
||||||
match '/@:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile, defaults: {page: 1}
|
match '/@:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile, defaults: {page: 1}
|
||||||
match '/@:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer
|
match '/@:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer
|
||||||
|
match '/@:username/q/:id', to: 'question#show', via: 'get', as: :show_user_question
|
||||||
match '/:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile_alt, defaults: {page: 1}
|
match '/:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile_alt, defaults: {page: 1}
|
||||||
match '/:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer_alt
|
match '/:username/a/:id', to: 'answer#show', via: 'get', as: :show_user_answer_alt
|
||||||
|
match '/:username/q/:id', to: 'question#show', via: 'get', as: :show_user_question_alt
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddAnswerCountToQuestions < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :questions, :answer_count, :integer, default: 0, null: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141201191324) do
|
ActiveRecord::Schema.define(version: 20141207194424) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20141201191324) do
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.integer "answer_count", default: 0, null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "questions", ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at", using: :btree
|
add_index "questions", ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at", using: :btree
|
||||||
|
|
Loading…
Reference in New Issue