fix broken pagination and wrong question count for deletion
This commit is contained in:
parent
e9ae442431
commit
84f80c824e
|
@ -5,6 +5,7 @@ class InboxController < ApplicationController
|
|||
@inbox = Inbox.where(user: current_user)
|
||||
.order(:created_at).reverse_order
|
||||
.paginate(page: params[:page])
|
||||
@inbox_count = Inbox.where(user: current_user).count
|
||||
if params[:author].present?
|
||||
begin
|
||||
@author = true
|
||||
|
@ -12,15 +13,21 @@ class InboxController < ApplicationController
|
|||
@inbox_author = current_user.inboxes.joins(:question)
|
||||
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
||||
.paginate(page: params[:page])
|
||||
@inbox_author_count = current_user.inboxes.joins(:question)
|
||||
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
||||
.count
|
||||
if @inbox_author.empty?
|
||||
flash[:info] = "No questions from @#{params[:author]} found, showing default entries instead!"
|
||||
@inbox
|
||||
@inbox_count
|
||||
else
|
||||
@inbox = @inbox_author
|
||||
@inbox_count = @inbox_author_count
|
||||
end
|
||||
rescue
|
||||
flash[:error] = "No user with the name @#{params[:author]} found, showing default entries instead!"
|
||||
@inbox
|
||||
@inbox_count
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
|
|
|
@ -25,5 +25,5 @@
|
|||
.panel-heading
|
||||
%h3.panel-title= t 'views.inbox.sidebar.actions.title'
|
||||
.panel-body
|
||||
%button.btn.btn-block.btn-danger{type: :button, id: @author ? 'ib-delete-all-author' : 'ib-delete-all', disabled: (Inbox.where(user: current_user).empty? ? 'disabled' : nil), data: { ib_count: Inbox.where(user: current_user).count }}= t 'views.inbox.sidebar.actions.button'
|
||||
%button.btn.btn-block.btn-danger{type: :button, id: @author ? 'ib-delete-all-author' : 'ib-delete-all', disabled: (Inbox.where(user: current_user).empty? ? 'disabled' : nil), data: { ib_count: @inbox_count }}= t 'views.inbox.sidebar.actions.button'
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ Rails.application.routes.draw do
|
|||
match '/notifications(/:type)', to: 'notifications#index', via: :get, as: :notifications, defaults: {type: 'all'}
|
||||
|
||||
match '/inbox', to: 'inbox#show', via: 'get'
|
||||
match '/inbox/:author', to: 'inbox#show', via: 'get'
|
||||
match '/inbox/:author/:page', to: 'inbox#show', via: 'get'
|
||||
|
||||
match '/user/:username(/p/:page)', to: 'user#show', via: 'get', defaults: {page: 1}
|
||||
match '/@:username(/p/:page)', to: 'user#show', via: 'get', as: :show_user_profile_alt, defaults: {page: 1}
|
||||
|
|
Loading…
Reference in New Issue