我正在使用 Ruby on Rails 3.2.9,我只是想使用state_machine gem。我有以下陈述:
class Article < ActiveRecord::Base
state_machine :attribute => :status, :initial => :unconfirmed do
state :confirmed, :value => 'confirmed'
state :unconfirmed, :value => 'unconfirmed'
event :confirm do
transition :unconfirmed => :confirmed
end
event :unconfirm do
transition :confirmed => :unconfirmed
end
end
end
我还有一个模型confirmed_at
属性,用于在切换到.Article
:status
:confirmed
如何将confirmed_at
属性初始化为当前时间?每次触发事件时,我应该如何将其设置为当前时间?confirmed_at
:confirm