diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 30dc1aa..8f61c8c 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -32,6 +32,21 @@ def create [[], 302, { 'location' => location }] end + def destroy + return require_authentication unless current_user + + return category_not_found unless find_category + + category_name = @category.name + request.session['flash'] = if @category.destroy + "Category '#{category_name}' deleted" + else + 'Failed to delete' + end + + [[], 302, { 'location' => '/categories' }] + end + private def find_category diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index fb952c8..f09f92d 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -16,12 +16,46 @@ <%= category.name %> + +