-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca0ccc0
commit 388ffe7
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
class Task < ApplicationRecord | ||
validates :action, presence: true, uniqueness: true | ||
after_validation :update_finished_at, if: :will_save_change_to_done? | ||
# only when finished_at attribute is nil | ||
def mark_as_done | ||
finished_at.nil? ? self.done = true : errors.add(:done, 'This task has already been marked as done') | ||
end | ||
|
||
private | ||
|
||
def update_finished_at | ||
self.finished_at = DateTime.now | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters