From 84f80c824ef9c3d434498cb842a77f54f0fb5b17 Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Fri, 17 Jul 2015 20:54:11 +0200 Subject: [PATCH] fix broken pagination and wrong question count for deletion --- app/controllers/inbox_controller.rb | 7 +++++++ app/views/inbox/_sidebar.html.haml | 2 +- config/routes.rb | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/inbox_controller.rb b/app/controllers/inbox_controller.rb index a63a4bce..6b4d7e03 100644 --- a/app/controllers/inbox_controller.rb +++ b/app/controllers/inbox_controller.rb @@ -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| diff --git a/app/views/inbox/_sidebar.html.haml b/app/views/inbox/_sidebar.html.haml index 024e73f1..be9baaef 100644 --- a/app/views/inbox/_sidebar.html.haml +++ b/app/views/inbox/_sidebar.html.haml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 6b00da95..3203aa7c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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}