mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 10:19:52 +01:00
added question#show thing and more...
This commit is contained in:
parent
a9f5ddab65
commit
7de522a82f
9 changed files with 74 additions and 16 deletions
12
Rakefile
12
Rakefile
|
@ -27,6 +27,18 @@ namespace :justask do
|
|||
end
|
||||
progress.increment
|
||||
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
|
||||
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
|
||||
Answer.all.each do |answer|
|
||||
|
|
6
app/controllers/question_controller.rb
Normal file
6
app/controllers/question_controller.rb
Normal file
|
@ -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,
|
||||
question: self.question)
|
||||
user.increment! :answered_count
|
||||
self.question.increment! :answer_count
|
||||
self.destroy
|
||||
end
|
||||
|
||||
def remove
|
||||
self.question.decrement! :answer_count
|
||||
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
|
||||
|
||||
self.question.destroy if self.question.answers.count == 1
|
||||
self.question.destroy if self.question.answer_count == 1
|
||||
self.destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
asked
|
||||
= time_ago_in_words(i.question.created_at)
|
||||
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
|
||||
.panel-body
|
||||
%textarea.form-control{name: 'ib-answer', 'data-id' => i.id}
|
||||
|
|
18
app/views/question/show.html.haml
Normal file
18
app/views/question/show.html.haml
Normal file
|
@ -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-heading
|
||||
.media
|
||||
- unless a.question.author_is_anonymous
|
||||
%a.pull-left{href: show_user_profile_path(a.question.user.screen_name)}
|
||||
%img.img-rounded.img-answerbox{src: gravatar_url(a.question.user)}
|
||||
.media-body
|
||||
%h6.text-muted.media-heading.answerbox-question-user
|
||||
= user_screen_name a.question.user, a.question.author_is_anonymous
|
||||
asked
|
||||
%a{href: show_user_answer_path(a.user.screen_name, a.id)}
|
||||
= time_ago_in_words(a.question.created_at)
|
||||
ago
|
||||
%p.answerbox-question-text= a.question.content
|
||||
- if @question.nil?
|
||||
.panel-heading
|
||||
.media
|
||||
- unless a.question.author_is_anonymous
|
||||
%a.pull-left{href: show_user_profile_path(a.question.user.screen_name)}
|
||||
%img.img-rounded.img-answerbox{src: gravatar_url(a.question.user)}
|
||||
.media-body
|
||||
%h6.text-muted.media-heading.answerbox-question-user
|
||||
= user_screen_name a.question.user, a.question.author_is_anonymous
|
||||
asked
|
||||
%a{href: show_user_answer_path(a.user.screen_name, a.id)}
|
||||
= time_ago_in_words(a.question.created_at)
|
||||
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
|
||||
%p= a.content
|
||||
- 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 '/@: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/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/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
|
||||
|
|
|
@ -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.
|
||||
|
||||
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
|
||||
enable_extension "plpgsql"
|
||||
|
@ -54,6 +54,7 @@ ActiveRecord::Schema.define(version: 20141201191324) do
|
|||
t.integer "user_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "answer_count", default: 0, null: false
|
||||
end
|
||||
|
||||
add_index "questions", ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at", using: :btree
|
||||
|
|
Loading…
Reference in a new issue