Skip to content

Commit 962b8e8

Browse files
Add turbo confirm prompt
1 parent 28ec1c8 commit 962b8e8

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/generators/tailwindcss/scaffold/templates/index.html.erb.tt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<%%= link_to "Show", <%= model_resource_name(singular_table_name) %>, class: "rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
2020
<%%= link_to "Edit", <%= edit_helper(singular_table_name, type: :path) %>, class: "rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
2121
<div class="inline-block">
22-
<%%= button_to "Destroy", <%= model_resource_name %>, method: :delete, class: "rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium" %>
22+
<%%= button_to "Destroy", <%= model_resource_name %>, method: :delete, class: "rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %>
2323
</div>
2424
</div>
2525
</div>

lib/generators/tailwindcss/scaffold/templates/show.html.erb.tt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
<%%= link_to "Edit this <%= human_name.downcase %>", <%= edit_helper(type: :path) %>, class: "mt-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
1313
<%%= link_to "Back to <%= human_name.pluralize.downcase %>", <%= index_helper %>_path, class: "ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
1414
<div class="inline-block ml-2">
15-
<%%= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, method: :delete, class: "mt-2 rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium" %>
15+
<%%= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, method: :delete, class: "mt-2 rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %>
1616
</div>
1717
</div>

test/lib/generators/tailwindcss/scaffold_generator_test.rb

+20
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,24 @@ class Tailwindcss::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCa
4646
end
4747
end
4848
end
49+
50+
test "adds a confirmation prompt to the destroy button when turbo is available" do
51+
::Turbo = Class.new
52+
53+
run_generator
54+
55+
assert_file "app/views/messages/show.html.erb" do |body|
56+
assert_match "data: { turbo_confirm: \"Are you sure?\" }", body, "confirmation prompt should be added for turbo"
57+
end
58+
59+
Object.send :remove_const, :Turbo
60+
end
61+
62+
test "doesn't add a confirmation prompt to the destroy button when turbo is not available" do
63+
run_generator
64+
65+
assert_file "app/views/messages/show.html.erb" do |body|
66+
assert_no_match "data: { turbo_confirm: \"Are you sure?\" }", body, "confirmation prompt shouldn't be added"
67+
end
68+
end
4969
end

0 commit comments

Comments
 (0)