Skip to content
This repository has been archived by the owner on Feb 22, 2021. It is now read-only.

Make sure to set link text when reflection is invalid. #110

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions app/controllers/reflections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,6 +37,7 @@ def create

redirect_to after_create_path
else
set_link_text_and_url
render :new
end
end
Expand All @@ -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