Skip to content

Commit

Permalink
Simplify ability handling via automatic resource loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Sep 6, 2024
1 parent 02a4e10 commit cb5863d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/controllers/vouchers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
class VouchersController < ApplicationController
before_action :set_voucher, only: [:invalidate]
authorize_resource except: [:create, :redeem]
load_and_authorize_resource
before_action :find_voucher, only: :invalidate

def current_ability
@current_ability ||= VoucherAbility.new(current_user)
end

def create
@voucher = Voucher.new(voucher_params)
set_related_data
authorize! :create, @voucher
respond_to do |format|
if @voucher.save
handle_successful_save(format)
Expand Down Expand Up @@ -39,7 +37,7 @@ def voucher_params
params.permit(:lecture_id, :role)
end

def set_voucher
def find_voucher
@voucher = Voucher.find_by(id: params[:id])
return if @voucher

Expand Down

0 comments on commit cb5863d

Please sign in to comment.