From 63e64a060d0a4e4c5451de4943dd999f930d1ad6 Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Mon, 15 Sep 2025 17:29:40 +0200 Subject: [PATCH] Use HTML5 validation for the URL --- app/controllers/webhooks_controller.rb | 16 ++++------------ app/views/webhooks/new.html.erb | 8 +++++++- test/controllers/webhooks_controller_test.rb | 2 -- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb index ddd0f09da..fceb37c5c 100644 --- a/app/controllers/webhooks_controller.rb +++ b/app/controllers/webhooks_controller.rb @@ -17,24 +17,16 @@ class WebhooksController < ApplicationController end def create - @webhook = @collection.webhooks.new(webhook_params) - - if @webhook.save - redirect_to @webhook - else - render :new, status: :unprocessable_entity - end + @webhook = @collection.webhooks.create!(webhook_params) + redirect_to @webhook end def edit end def update - if @webhook.update(webhook_params.except(:url)) - redirect_to @webhook - else - render :edit, status: :unprocessable_entity - end + @webhook.update!(webhook_params.except(:url)) + redirect_to @webhook end def destroy diff --git a/app/views/webhooks/new.html.erb b/app/views/webhooks/new.html.erb index 98c5642f7..780088117 100644 --- a/app/views/webhooks/new.html.erb +++ b/app/views/webhooks/new.html.erb @@ -11,7 +11,13 @@ <%= form.text_field :name, required: true, autofocus: true, class: "input", placeholder: "Name your Webhook…", data: { action: "keydown.esc@document->form#cancel" } %> - <%= form.text_field :url, required: true, class: "input", placeholder: "https://example.com", data: { action: "keydown.esc@document->form#cancel" } %> + <%= form.url_field :url, + required: true, + pattern: "https?://.*", + title: "Must be an http:// or https:// URL", + class: "input", + placeholder: "https://example.com", + data: { action: "keydown.esc@document->form#cancel" } %>
<%= form.label :actions %> diff --git a/test/controllers/webhooks_controller_test.rb b/test/controllers/webhooks_controller_test.rb index aa8696fa5..54d50a31b 100644 --- a/test/controllers/webhooks_controller_test.rb +++ b/test/controllers/webhooks_controller_test.rb @@ -56,7 +56,6 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest end assert_response :unprocessable_entity - assert_select "form" end test "edit" do @@ -91,7 +90,6 @@ class WebhooksControllerTest < ActionDispatch::IntegrationTest } assert_response :unprocessable_entity - assert_select "form" assert_no_changes -> { webhook.reload.url } do patch collection_webhook_path(webhook.collection, webhook), params: {