使用AASM Gem时是否可以在进入初始状态时调用方法?我希望在spam_check
提交评论时调用该方法,但它似乎不起作用。
class Comment < ActiveRecord::Base
include AASM
aasm_column :state
aasm_initial_state :submitted
aasm_state :submitted, :enter => :spam_check
aasm_state :approved
aasm_state :rejected
aasm_event :ham do
transitions :to => :approved, :from => [:submitted, :rejected]
end
aasm_event :spam do
transitions :to => :rejected, :from => [:submitted, :approved]
end
def spam_check
# Mark the comment as spam or ham...
end
end