diff --git a/app/controllers/models_controller.rb b/app/controllers/models_controller.rb
index 620853b9f..dae1c0aba 100644
--- a/app/controllers/models_controller.rb
+++ b/app/controllers/models_controller.rb
@@ -1,3 +1,5 @@
+require 'fileutils'
+
class ModelsController < ApplicationController
before_action :get_library, except: [:index, :bulk_edit, :bulk_update]
before_action :get_model, except: [:bulk_edit, :bulk_update, :index]
@@ -84,6 +86,11 @@ class ModelsController < ApplicationController
def destroy
@model.destroy
+
+ # Delete directory corresponding to model
+ pathname = File.join(@library.path, @model.path)
+ FileUtils.remove_dir(pathname) if File.exist?(pathname)
+
redirect_to library_path(@library)
end
diff --git a/app/views/application/_model.html.erb b/app/views/application/_model.html.erb
index 718f021a0..ab1712c9f 100644
--- a/app/views/application/_model.html.erb
+++ b/app/views/application/_model.html.erb
@@ -23,6 +23,7 @@
<%= link_to "Open", [model.library, model], {class: "btn btn-primary btn-sm"} %>
<%= link_to "Edit", edit_library_model_path(model.library, model), {class: "btn btn-outline-secondary btn-sm"} %>
+ <%= link_to "Delete", library_model_path(model.library, model), {method: :delete, class: "btn btn-outline-danger btn-sm", data: {confirm: "This will delete files. Are you sure you want to continue?"}} %>
diff --git a/app/views/models/show.html.erb b/app/views/models/show.html.erb
index c00db86d0..0adb09b55 100644
--- a/app/views/models/show.html.erb
+++ b/app/views/models/show.html.erb
@@ -73,6 +73,7 @@
<%= button_tag "Organize Files", class: "btn btn-warning", "data-bs-toggle": "modal", "data-bs-target": "#confirm-move" %>
<%= link_to "Search Yeggi", "https://yeggi.com/q/#{ERB::Util.url_encode(@model.name)}/", class: 'btn btn-secondary' %>
<% end %>
+ <%= link_to "Delete", library_model_path(@library, @model), {method: :delete, class: "btn btn-danger", data: {confirm: "This will delete files. Are you sure you want to continue?"}} %>
<% end %>
<%= card(:secondary, 'Notes') do %>