From 5ab17cf69b547613e1055eb20ee9a8386976d992 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Fri, 24 Apr 2020 00:54:32 +0200 Subject: [PATCH] Added MealsController#destroy --- app/controllers/meals_controller.rb | 1 + app/views/meals/_index.html.erb | 2 +- app/views/meals/_show.html.erb | 2 +- app/views/meals/destroy.js.erb | 4 ++++ 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 app/views/meals/destroy.js.erb diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb index 0f6c42b..9808113 100644 --- a/app/controllers/meals_controller.rb +++ b/app/controllers/meals_controller.rb @@ -44,6 +44,7 @@ class MealsController < ApplicationController end def destroy + flash[:notice] = 'Deleted meal' if @meal.destroy end def edit_notes diff --git a/app/views/meals/_index.html.erb b/app/views/meals/_index.html.erb index 8a4f246..16ade3a 100644 --- a/app/views/meals/_index.html.erb +++ b/app/views/meals/_index.html.erb @@ -4,7 +4,7 @@ <% @meals.group_by { |m| m.eaten_at ? m.eaten_at.to_date : Date.current } .sort_by {|k,v| k }.reverse.each do |date, meals| %> - +

<%= date == Date.current ? 'Today' : date.strftime('%F') %>

diff --git a/app/views/meals/_show.html.erb b/app/views/meals/_show.html.erb index c1ba01d..c745806 100644 --- a/app/views/meals/_show.html.erb +++ b/app/views/meals/_show.html.erb @@ -32,7 +32,7 @@ <% end %> <% end %> - + <% end %> diff --git a/app/views/meals/destroy.js.erb b/app/views/meals/destroy.js.erb new file mode 100644 index 0000000..88e0db4 --- /dev/null +++ b/app/views/meals/destroy.js.erb @@ -0,0 +1,4 @@ +<% if @meal.destroyed? %> + $('tr[id=meal-<%= @meal.id %>]').nextUntil(':not(.ingredient)').addBack().remove(); + $('#meals').find('tr.date + tr.date').prev().remove(); +<% end %>