From be33f1f6afcb08a5945bce4add0ae05141321d5e Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Sat, 5 May 2018 22:59:12 +0900 Subject: [PATCH] [phase-4]add delete operation --- app/controllers/glossary_terms_controller.rb | 7 ++++++- app/views/glossary_terms/show.html.erb | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index 21ec472..b60ac9a 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -1,6 +1,6 @@ class GlossaryTermsController < ApplicationController - before_action :find_term_from_id, only: [:show, :edit, :update] + before_action :find_term_from_id, only: [:show, :edit, :update, :destroy] def index @glossary_terms = GlossaryTerm.all @@ -30,6 +30,11 @@ class GlossaryTermsController < ApplicationController rescue ActiveRecord::StaleObjectError flash.now[:error] = l(:notice_locking_conflict) end + + def destroy + @term.destroy + redirect_to glossary_terms_path + end # Find the term whose id is the :id parameter def find_term_from_id diff --git a/app/views/glossary_terms/show.html.erb b/app/views/glossary_terms/show.html.erb index 7fc0140..85a366b 100644 --- a/app/views/glossary_terms/show.html.erb +++ b/app/views/glossary_terms/show.html.erb @@ -1,5 +1,7 @@
<%= link_to l(:button_edit), edit_glossary_term_path, class: 'icon icon-edit' %> + <%= link_to l(:button_delete), glossary_term_path, method: :delete, + data: {confirm: l(:text_are_you_sure)}, class: 'icon icon-del' %>

<%=l :label_glossary_term %> #<%= @term.id %>