Added amount check for payments#new

This commit is contained in:
rishabhptr 2017-10-02 20:08:30 +05:30 committed by Stella Rouzi
parent 72afae6f2f
commit 3b27a2a8fb

View file

@ -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