diff --git a/app/controllers/concerns/finders.rb b/app/controllers/concerns/finders.rb index 643d4c7..6ad7216 100644 --- a/app/controllers/concerns/finders.rb +++ b/app/controllers/concerns/finders.rb @@ -1,6 +1,13 @@ module Concerns::Finders private + def find_meal + @meal = Meal.find(params[:id]) + @project = @meal.project + rescue ActiveRecord::RecordNotFound + render_404 + end + def find_food @food = Food.find(params[:id]) @project = @food.project diff --git a/app/controllers/meals_controller.rb b/app/controllers/meals_controller.rb index 8315068..9265428 100644 --- a/app/controllers/meals_controller.rb +++ b/app/controllers/meals_controller.rb @@ -39,6 +39,7 @@ class MealsController < ApplicationController end def toggle_eaten + @meal.toggle_eaten! end private diff --git a/app/models/meal.rb b/app/models/meal.rb index c36ade4..3cf1e01 100644 --- a/app/models/meal.rb +++ b/app/models/meal.rb @@ -17,4 +17,8 @@ class Meal < ActiveRecord::Base errors.add(:ingredients, :duplicated_ingredient) end end + + def toggle_eaten! + update(eaten_at: self.eaten_at ? nil : DateTime.current) + end end diff --git a/app/views/meals/_index.html.erb b/app/views/meals/_index.html.erb index 244557e..e199011 100644 --- a/app/views/meals/_index.html.erb +++ b/app/views/meals/_index.html.erb @@ -1,38 +1,16 @@ <% if @meals.any? { |m| m.persisted? } %>
+ <%= date == Date.current ? 'Today' : date.strftime('%F') %>+ |
+ |
- <%= "#{t '.label_meal'} ##{index+1}" %>
- <% if m.eaten_at %>
- <%= " - #{m.eaten_at.time}" %>
- <%= link_to '', toggle_eaten_meal_path(m),
- {remote: true, class: "icon icon-close"} %>
- <% else %>
- <%= link_to l(:button_eat), toggle_eaten_meal_path(m),
- {remote: true, class: "icon icon-ok"} %>
- <% end %>
- <%= link_to l(:button_note), note_meal_path(m),
- {remote: true, class: "icon icon-wiki-page"} %>
-
- <%= meal_links(m) %>
-
- |
- |
- <%= i.food.name %> - | -- <%= adjust_ingredient_links(i) { raw " #{i.amount} " } %> - | -
+ <%= "#{t '.label_meal'} ##{index+1}" %>
+ <% if m.eaten_at %>
+ <%= " - #{m.eaten_at.time}" %>
+ <%= link_to '', toggle_eaten_meal_path(m),
+ {remote: true, method: :post, class: "icon icon-close"} %>
+ <% else %>
+ <%= link_to l(:button_eat), toggle_eaten_meal_path(m),
+ {remote: true, method: :post, class: "icon icon-ok"} %>
+ <% end %>
+ <%= link_to l(:button_note), note_meal_path(m),
+ {remote: true, class: "icon icon-wiki-page"} %>
+
+ <%= meal_links(m) %>
+
+ |
+|
+ <%= i.food.name %> + | ++ <%= adjust_ingredient_links(i) { raw " #{i.amount} " } %> + | +