Use HTML5 validation for the URL
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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" } %>
|
||||
</h2>
|
||||
|
||||
<%= 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" } %>
|
||||
|
||||
<div class="flex flex-column align-start full-width">
|
||||
<%= form.label :actions %>
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user