# On doing "Question.create().fire_answered"
class Question < ApplicationRecord
state_machine initial: :created do
# this callback definition gives error as:
# "ArgumentError: wrong number of arguments (given 1, expected 0)" from line 'def analyze'.
after_transition on: :fire_answered, do: [:analyze]
# this callback definition works.
# after_transition on: :fire_answered { |q| q.analyze }
# if 'analyze' is not state based method than both works.
event :fire_answered do
transition from: :created, to: :answered
end
state :answered do
validates_presence_of :response_time
def analyze
puts '*** Inside analyze ***'
end
end
end
end
From below code :