Retrospring/app/controllers/inbox_controller.rb

32 lines
1.0 KiB
Ruby
Raw Normal View History

2014-11-10 22:10:41 -08:00
class InboxController < ApplicationController
before_filter :authenticate_user!
2014-11-10 22:10:41 -08:00
def show
@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