From 3b27a2a8fbded28ef9d173f932ee294c6aa0bb42 Mon Sep 17 00:00:00 2001 From: rishabhptr Date: Mon, 2 Oct 2017 20:08:30 +0530 Subject: [PATCH] Added amount check for payments#new --- app/controllers/payments_controller.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 8faebef7..322ed397 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -3,7 +3,6 @@ class PaymentsController < ApplicationController load_and_authorize_resource load_resource :conference, find_by: :short_title authorize_resource :conference_registrations, class: Registration - before_action :check_amount, only: [:new] def index @payments = current_user.payments @@ -11,6 +10,9 @@ class PaymentsController < ApplicationController def new @total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false) + if @total_amount_to_pay.zero? + raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment) + end @unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference) end @@ -29,11 +31,6 @@ class PaymentsController < ApplicationController end end - def check_amount - @total_amount_to_pay = Ticket.total_price(@conference, current_user, paid: false) - redirect_to root_path if @total_amount_to_pay.zero? - end - private def payment_params