This commit is contained in:
nilsding 2014-12-07 14:29:35 +01:00
parent c107aafa5f
commit 8479f308ac
3 changed files with 4 additions and 5 deletions

View File

@ -32,6 +32,8 @@ namespace :justask do
Answer.all.each do |answer| Answer.all.each do |answer|
begin begin
smiles = Smile.where(answer: answer).count smiles = Smile.where(answer: answer).count
comments = Comment.where(answer: answer).count
answer.comment_count = comments
answer.smile_count = smiles answer.smile_count = smiles
answer.save! answer.save!
end end

View File

@ -102,12 +102,8 @@ class User < ActiveRecord::Base
end end
def comment(answer, content) def comment(answer, content)
Comment.create(user: self, answer: answer, content: content) Comment.create!(user: self, answer: answer, content: content)
increment! :commented_count increment! :commented_count
answer.increment! :comment_count answer.increment! :comment_count
end end
def destroy_comment(comment)
# TODO: implement this
end
end end

View File

@ -33,6 +33,7 @@ Rails.application.routes.draw do
match '/destroy_friend', to: 'friend#destroy', via: :post, as: :destroy_friend match '/destroy_friend', to: 'friend#destroy', via: :post, as: :destroy_friend
match '/create_smile', to: 'smile#create', via: :post, as: :create_smile match '/create_smile', to: 'smile#create', via: :post, as: :create_smile
match '/destroy_smile', to: 'smile#destroy', via: :post, as: :destroy_smile match '/destroy_smile', to: 'smile#destroy', via: :post, as: :destroy_smile
match '/create_comment', to: 'comment#create', via: :post, as: :create_comment
end end
match '/inbox', to: 'inbox#show', via: 'get' match '/inbox', to: 'inbox#show', via: 'get'