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 %> + +
+ + + +
<% end %> + diff --git a/config.ru b/config.ru index f73ff2e..5df1b23 100644 --- a/config.ru +++ b/config.ru @@ -36,6 +36,7 @@ use Frack::Router do get '/categories/new' => 'categories#new' post '/categories' => 'categories#create' get '/categories/show' => 'categories#show' + delete '/categories' => 'categories#destroy' get '/products' => 'products#index' get '/products/new' => 'products#new' post '/products' => 'products#create'