2014-11-10 12:56:30 -08:00
|
|
|
class Ajax::QuestionController < ApplicationController
|
|
|
|
def create
|
|
|
|
params.require :question
|
|
|
|
params.require :anonymousQuestion
|
|
|
|
params.require :rcpt
|
|
|
|
|
2014-11-10 14:46:38 -08:00
|
|
|
question = Question.create!(content: params[:question],
|
2014-11-10 21:51:56 -08:00
|
|
|
author_is_anonymous: params[:anonymousQuestion],
|
2014-11-10 22:08:59 -08:00
|
|
|
user: current_user)
|
2014-11-10 12:56:30 -08:00
|
|
|
|
2014-11-10 22:18:34 -08:00
|
|
|
unless current_user.nil?
|
|
|
|
current_user.increment! :asked_count unless params[:anonymousQuestion] == 'true'
|
|
|
|
end
|
|
|
|
|
2014-12-07 11:13:45 -08:00
|
|
|
if params[:rcpt] == 'followers'
|
|
|
|
unless current_user.nil?
|
|
|
|
current_user.followers.each do |f|
|
|
|
|
Inbox.create!(user_id: f.id, question_id: question.id, new: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Inbox.create!(user_id: params[:rcpt], question_id: question.id, new: true)
|
|
|
|
end
|
2014-11-10 12:56:30 -08:00
|
|
|
|
|
|
|
@status = :okay
|
|
|
|
@message = "Question asked successfully."
|
|
|
|
@success = true
|
|
|
|
end
|
|
|
|
end
|