如何返回 aasm 事件的值?
如何使 aasm 事件返回布尔值以外的值?我正在使用 aasm
2.2.0有一个 MusicPlayer 模型,它在启动时随机播放歌曲
aasm_state :started, :after_enter => :play_song
aasm_state :stopped
aasm_event :start do
:transitions :from => :stopped, :to => :started
end
def play_song
# select and play a song randomly and return the song object
end
现在,如果我想返回启动播放器时当前正在播放的歌曲,如何通过“play_song”方法来实现?
How do I make an aasm event return a value other than boolean? I'm using aasm 2.2.0
E.g. There is a MusicPlayer model which randomly plays a song when started
aasm_state :started, :after_enter => :play_song
aasm_state :stopped
aasm_event :start do
:transitions :from => :stopped, :to => :started
end
def play_song
# select and play a song randomly and return the song object
end
Now if I want to return the song that is currently being played on starting the player, how do I do it through the 'play_song' method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能那样做。返回状态用于指示转换是否成功。但我很好奇你有什么用例需要它。
但是您可以包装状态转换并使用由
play_song
方法设置的变量,如下所示:You can't do that. The return status is used to indicate if the transition was sussessful or not. But I'm curious what use case you have that you need that.
But you can wrap the state transition and use a variable that's set by the
play_song
method, like this: