Skip to content

Commit 4613007

Browse files
drusepthclaude
andcommitted
Add delete-all-tags button per content type on /my/data/tags
- Add remove_all action to delete all tags for a content type - Add confirmation dialog before bulk deletion - Add before_action :authenticate_user! to PageTagsController for security 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fc98597 commit 4613007

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

app/controllers/page_tags_controller.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class PageTagsController < ApplicationController
2+
before_action :authenticate_user!
3+
24
def update
35
raise "placeholder"
46
end
@@ -34,6 +36,24 @@ def remove
3436
return redirect_back fallback_location: root_path, notice: 'Tag(s) deleted successfully.'
3537
end
3638

39+
# Remove ALL tags for a specific content type
40+
def remove_all
41+
return unless params.key?(:page_type)
42+
43+
deleted_count = PageTag.where(
44+
page_type: params[:page_type],
45+
user_id: current_user.id
46+
).count
47+
48+
PageTag.where(
49+
page_type: params[:page_type],
50+
user_id: current_user.id
51+
).destroy_all
52+
53+
redirect_back fallback_location: root_path,
54+
notice: "Deleted #{deleted_count} #{params[:page_type].downcase} tag(s) successfully."
55+
end
56+
3757
# Destroy a specific tag by ID
3858
def destroy
3959
PageTag.find_by(id: params[:id], user_id: current_user.id).destroy!

app/views/data/tags.html.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@
8484
</div>
8585
</div>
8686
<% end %>
87+
88+
<div class="right-align" style="margin-top: 20px; padding-top: 15px; border-top: 1px solid #eee;">
89+
<%= link_to "Delete all #{content_type.name.downcase} tags",
90+
tag_remove_all_path(page_type: content_type.name),
91+
data: {
92+
confirm: "Are you sure? This will permanently delete ALL #{grouped_tags.values.length} tags from your #{content_type.name.pluralize.downcase}. This cannot be undone."
93+
},
94+
class: 'btn red white-text' %>
95+
</div>
8796
</div>
8897
</li>
8998
<% end %>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
get '/scratchpad', to: 'main#notes', as: :notes
150150

151151
get 'tag/remove', to: 'page_tags#remove'
152+
get 'tag/remove_all', to: 'page_tags#remove_all'
152153
# post 'tag/:slug/update', to: 'page_tags#update', as: :update_tag
153154
post '/tag/:tag/rename', to: 'page_tags#rename', as: :rename_tag
154155
delete 'tag/:id/destroy', to: 'page_tags#destroy', as: :destroy_specific_tag

0 commit comments

Comments
 (0)