Skip to content

Commit

Permalink
Only allow creation of log if you're not already working
Browse files Browse the repository at this point in the history
  • Loading branch information
dmastylo committed Apr 12, 2014
1 parent e09d090 commit 4680e78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/time_spents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ class TimeSpentsController < ApplicationController
before_filter :user_owns_time_spent, only: [:edit, :update, :destroy]

def create
if current_user.currently_working?
flash[:error] = "You are already working!"
redirect_to root_path
end

@time_spent = current_user.time_spents.create(time_spent_params)
@time_spent.set_amount_paid

Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def projects_sorted_by_recent_work

# Time Spents
# ========================================================
def currently_working?
!time_spents.where("finished_at IS NULL").blank?
end

def working_time_spent(existing_task)
existing_task ? time_spents.last : time_spents.build
end
Expand Down

0 comments on commit 4680e78

Please sign in to comment.