diff --git a/app/controllers/admin/vouchers_controller.rb b/app/controllers/admin/vouchers_controller.rb index e97a2c3cbcf..e60e5796d16 100644 --- a/app/controllers/admin/vouchers_controller.rb +++ b/app/controllers/admin/vouchers_controller.rb @@ -9,13 +9,11 @@ def new end def create - case params[:voucher][:voucher_type] - when "Vouchers::FlatRate" - @voucher = - Vouchers::FlatRate.create(permitted_resource_params.merge(enterprise: @enterprise)) - when "Vouchers::PercentageRate" - @voucher = - Vouchers::PercentageRate.create(permitted_resource_params.merge(enterprise: @enterprise)) + voucher_type = params[:voucher][:voucher_type] + if Voucher::TYPES.include?(voucher_type) + @voucher = voucher_type.constantize.create( + permitted_resource_params.merge(enterprise: @enterprise) + ) else @voucher.errors.add(:type) return render_error