2014-11-10 22:10:41 -08:00
|
|
|
class InboxController < ApplicationController
|
2014-11-11 10:53:25 -08:00
|
|
|
before_filter :authenticate_user!
|
|
|
|
|
2014-11-10 22:10:41 -08:00
|
|
|
def show
|
2015-07-17 11:29:19 -07:00
|
|
|
@inbox = Inbox.where(user: current_user)
|
|
|
|
.order(:created_at).reverse_order
|
|
|
|
.paginate(page: params[:page])
|
|
|
|
if params[:author].present?
|
|
|
|
begin
|
|
|
|
@author = true
|
|
|
|
@target_user = User.find_by_screen_name params[:author]
|
|
|
|
@inbox_author = current_user.inboxes.joins(:question)
|
|
|
|
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
|
|
|
.paginate(page: params[:page])
|
|
|
|
if @inbox_author.empty?
|
|
|
|
flash[:info] = "No questions from @#{params[:author]} found, showing default entries instead!"
|
|
|
|
@inbox
|
|
|
|
else
|
|
|
|
@inbox = @inbox_author
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
flash[:error] = "No user with the name @#{params[:author]} found, showing default entries instead!"
|
|
|
|
@inbox
|
|
|
|
end
|
|
|
|
end
|
2015-02-12 13:09:11 -08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
2014-11-10 22:10:41 -08:00
|
|
|
end
|
|
|
|
end
|