From 995dcfe8e6e2a6498e24ed9a47749a29ef81946e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 3 Nov 2025 15:00:15 +0100 Subject: [PATCH] Simplify setup and pull query-prevention into model --- app/controllers/webhooks/activations_controller.rb | 12 ++++-------- app/models/webhook.rb | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/webhooks/activations_controller.rb b/app/controllers/webhooks/activations_controller.rb index 02205efb6..87b05cf91 100644 --- a/app/controllers/webhooks/activations_controller.rb +++ b/app/controllers/webhooks/activations_controller.rb @@ -1,14 +1,10 @@ class Webhooks::ActivationsController < ApplicationController before_action :ensure_admin - before_action :set_webhook def create - @webhook.activate unless @webhook.active? - redirect_to @webhook - end + webhook = Webhook.find(params[:webhook_id]) + webhook.activate - private - def set_webhook - @webhook = Webhook.find(params[:webhook_id]) - end + redirect_to webhook + end end diff --git a/app/models/webhook.rb b/app/models/webhook.rb index 9a103d9bc..1af19cd47 100644 --- a/app/models/webhook.rb +++ b/app/models/webhook.rb @@ -40,11 +40,11 @@ class Webhook < ApplicationRecord validate :validate_url def activate - update_columns active: true + update! active: true unless active? end def deactivate - update_columns active: false + update! active: false end def renderer