Try potential fix for aasm 5.x

This commit is contained in:
Jyri-Petteri Paloposki 2020-08-19 02:42:36 +03:00
parent 69b24c3af7
commit 399e2c0b76
2 changed files with 5 additions and 5 deletions

View file

@ -12,8 +12,8 @@ class RecurringTodo < ApplicationRecord
include AASM
aasm :column => :state do
state :active, :initial => true, :before_enter => Proc.new { |t| t.occurrences_count = 0 }
state :completed, :before_enter => Proc.new { |t| t.completed_at = Time.zone.now }, :before_exit => Proc.new { |t| t.completed_at = nil }
state :active, :initial => true, :before_enter => Proc.new { occurrences_count = 0 }
state :completed, :before_enter => Proc.new { completed_at = Time.zone.now }, :before_exit => Proc.new { completed_at = nil }
event :complete do
transitions :to => :completed, :from => [:active]

View file

@ -70,13 +70,13 @@ class Todo < ApplicationRecord
# state machine
include AASM
aasm_initial_state = Proc.new { |t| (t.show_from && t.user && (t.show_from > t.user.date)) ? :deferred : :active}
aasm_initial_state = Proc.new { (show_from && user && (show_from > user.date)) ? :deferred : :active}
aasm :column => :state do
state :active
state :completed, :before_enter => Proc.new { |t| t.completed_at = Time.zone.now }, :before_exit => Proc.new { |t| t.completed_at = nil}
state :deferred, :before_exit => Proc.new { |t| t[:show_from] = nil }
state :completed, :before_enter => Proc.new { completed_at = Time.zone.now }, :before_exit => Proc.new { completed_at = nil}
state :deferred, :before_exit => Proc.new { show_from = nil }
state :pending
event :defer do