- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 AASM 来管理状态,并且只是想要一些列来跟踪状态更改的时间,但回调似乎不起作用。当然,问题可能出在我的方法上,我只是不确定。
aasm_state :active, :after => :activate
aasm_state :inactive
aasm_state :deactivated, :after => :deactivate
aasm_event :active do
transitions :to => :active, :from => [:inactive]
transitions :to => :active, :from => [:deactivated]
end
aasm_event :deactivated do
transitions :to => :deactivated, :from => [:active]
end
def activate
activated_at = Time.now
end
def deactivate
deactivated_at = Time.now
end
最佳答案
在 Rails 3 版本的 AASM 中,您需要将回调应用于转换事件,而不是状态。所以你的代码可以是 -
aasm_state :active
aasm_event :active, :after => :activate do
transitions :to => :active, :from => [:inactive]
transitions :to => :active, :from => [:deactivated]
end
关于ruby-on-rails - AASM 回调不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5998528/
假设我有这个类(直接取自 aasm 文档): class Job true state :running state :cleaning event :run do
我正在使用 AASM 来管理状态,并且只是想要一些列来跟踪状态更改的时间,但回调似乎不起作用。当然,问题可能出在我的方法上,我只是不确定。 aasm_state :active, :a
我正在使用AASM。根据条件,是否可能有2种不同的状态?例如: aasm_event :completes do transitions :to => condition? ? :complete
我正在使用 aasm (以前是 acts_as_state_machine)我的 Rails 4 应用程序中的 gem。我的 Post 模型上有这样的东西 ... aasm column: :
我正在使用 AASM .是否可以从任何状态转换?例如: aasm_event :publish do transitions :to => :publish, :from => ANY_STATE
我在 Rails 中有一个现有模型,我想向其中添加 AASM 状态。 根据我的理解,我应该先通过迁移将一个状态列添加到我的数据库中,然后再将一些状态添加到我的 Rails 模型中。如何根据另一列中的值
如何使 aasm 事件返回 bool 值以外的值?我正在使用 aasm 2.2.0 例如有一个 MusicPlayer 模型,它在启动时随机播放一首歌曲 aasm_state :started, :a
假设有一个对象有4个状态 :new :in_process :done :verified 还有一个方法只应在对象处于大于:in_process的状态时执行 我该如何进行这项检查?我想这可能是什么 d
如何在 AASM 中调用状态更改方法? 我想在以下模型中状态转换为付费时调用 update_foo: class Foo :incomplete, :to => :paid end def
我正在使用 AASM 来管理我的用户模型中的状态。 我想通过编辑操作改变状态。 为此,我在表单中使用了 User.aasm_states_for_select 方法填充状态的选择输入。当我点击提交按钮
我一直在使用 AASM在我当前的项目中制作状态机,想知道自动调用事件并进入下一个状态的最佳方式是什么? 我正在考虑两种方法: 设置后台作业以定期检查是否满足某些条件,从而调用事件以进入下一个状态。 让
我想在每次状态转换后调用 2 个方法。现在我正在做: aasm_event :nominate_for_publishing, :before => [:set_state_last_update
我想知道这个 gem 是否提供了一种保存状态历史的方法。我可能可以通过为每个事件添加回调来做到这一点,但我想知道其他人对这种方法的看法。 最佳答案 我最近看了这个,我找到的两个解决方案是 the as
当在状态转换的成功或进入阶段调用的方法抛出错误时,捕获此错误并确保状态恢复到先前状态的最佳方法是什么。 我正在使用 AASM gem。 最佳答案 如何使用 :guard 选项来确保可以执行转换?如果
我有两个事件: event :event1, after: :event2! do transitions to: :state2, from: :state1, guard: proc {som
我正在尝试重构一个 super 模型,该模型具有相当多行与状态和转换相关的 ActsAsStateMachine 代码,我希望将其重构为模块调用 CallStates。 #in lib/CallSta
我成功地将最新的 AASM gem 集成到一个应用程序中,并使用它来创建一个向导。就我而言,我有一个模型订单 class Order :destroy named_scope :with_use
在 state_machine我曾经做过 state :cancelled do validates_presence_of :user end 如果用户不在,它会自动取消转换。 我们如何为 aa
有没有办法定义在任何情况下在进入状态(例如 has_legs? )之前检查的守卫(例如 running )? 在所有可能的回调列表中,有事件和转换的守卫,但没有事件的守卫。 我试图对模型进行条件验证。
我的问题非常简单:如何更改按钮单击时的 aasm 转换?我应该在我的观点中加入什么? 我有两个按钮:批准和拒绝。我的状态如下所示: aasm :column => 'state' do s
我是一名优秀的程序员,十分优秀!