retrospring/app/controllers/answer_controller.rb
2015-05-05 02:36:57 +05:30

21 lines
997 B
Ruby

class AnswerController < ApplicationController
def show
@answer = Answer.find(params[:id])
@display_all = true
if user_signed_in?
notif = Notification.where(target_type: "Answer", target_id: @answer.id, recipient_id: current_user.id, new: true).first
unless notif.nil?
notif.new = false
notif.save
end
notif = Notification.where(target_type: "Comment", target_id: @answer.comments.pluck(:id), recipient_id: current_user.id, new: true)
notif.update_all(new: false) unless notif.empty?
notif = Notification.where(target_type: "Smile", target_id: @answer.smiles.pluck(:id), recipient_id: current_user.id, new: true)
notif.update_all(new: false) unless notif.empty?
# @answer.comments.smiles throws
notif = Notification.where(target_type: "CommentSmile", target_id: @answer.comment_smiles.pluck(:id), recipient_id: current_user.id, new: true)
notif.update_all(new: false) unless notif.empty?
end
end
end