From 8c27c57e071360e832120d6454477e96a017b4b9 Mon Sep 17 00:00:00 2001 From: Garrett Martin Date: Tue, 13 Feb 2018 21:41:02 -0600 Subject: [PATCH] Make sure to set link text when reflection is invalid. --- app/controllers/reflections_controller.rb | 24 +++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/reflections_controller.rb b/app/controllers/reflections_controller.rb index 6d0ec1c..d46e1a3 100644 --- a/app/controllers/reflections_controller.rb +++ b/app/controllers/reflections_controller.rb @@ -7,17 +7,12 @@ def new TodoList.today(current_user) @daily_snapshot = @todo_list.daily_snapshot - @reflecting_on_today = @todo_list == TodoList.today(current_user) - @link_text, @link_url = if @reflecting_on_today - ["Go back to today's tasks", today_path] - else - ["Go back", day_path(@daily_snapshot.date)] - end + set_link_text_and_url - if Reflection.today(current_user).present? && @reflecting_on_today + if Reflection.today(current_user).present? && reflecting_on_today? flash[:error] = 'You already wrote your reflection for today.' redirect_to dashboard_path - elsif TodoList.today(current_user).blank? && @reflecting_on_today + elsif TodoList.today(current_user).blank? && reflecting_on_today? flash[:error] = 'You must start your tasks for today before writing a reflection.' redirect_to dashboard_path end @@ -42,6 +37,7 @@ def create redirect_to after_create_path else + set_link_text_and_url render :new end end @@ -68,4 +64,16 @@ def reflection_params :date ) end + + def reflecting_on_today? + @todo_list == TodoList.today(current_user) + end + + def set_link_text_and_url + @link_text, @link_url = if reflecting_on_today? + ["Go back to today's tasks", today_path] + else + ["Go back", day_path(@daily_snapshot.date)] + end + end end