Questions tagged [aasm]

A library for adding finite state machines to Ruby classes.

Started as the acts_as_state_machine plugin but has evolved into a more generic library that no longer targets only ActiveRecord models.

Supports

  • States
  • Machines
  • Events
  • Transitions
125 questions
31
votes
2 answers

AASM: Transitions from any state?

I am using AASM. Is it possible to transition from any state? For example: aasm_event :publish do transitions :to => :publish, :from => ANY_STATE end I know that it is possible to pass an array of states to :from, but this isn't what I'm after. I…
gjb
  • 5,917
  • 7
  • 41
  • 70
10
votes
1 answer

state_machine vs aasm gems for app ruby on rails 3.2

I need a state machine for a message private system and order status system. you can see these two gems: https://github.com/pluginaweek/state_machine https://github.com/rubyist/aasm Edited.. I'm using mongoid with mongodb database What gem is most…
hyperrjas
  • 10,278
  • 22
  • 91
  • 188
9
votes
4 answers

Persisting the state column on transition using rubyist-aasm (acts as state machine)

What is the best way to persist the object's state to the database on a transition using aasm? I had thought that this would happen automatically but this doesn't seem to be the case. (Edit: when I manually save the object, the state column does get…
Angela
  • 2,856
  • 1
  • 28
  • 37
8
votes
1 answer

Validating a finite state machine (using AASM) on Rails

I'm using AASM by Rubyist to build a 4-step wizard for an AR object. According to the state of the object, there are different validations that need to be done. What is the smartest way to validate an object according to it's state on a certain…
Javier
  • 2,451
  • 4
  • 36
  • 55
8
votes
4 answers

best practice for gems like workflow or AASM

i would like to know how you guys use the workflow or the AASM gem in the controller if you want to update all attributes, but also need the workflow/AASM callbacks to fire properly. currently, i use it like this: class ModelController <…
fluxsaas
  • 997
  • 2
  • 11
  • 27
8
votes
3 answers

Multiple state machines in one model?

I have a model that represents a registration process, which needs to track the progression of several processes (background checks, interviews, information collection...). Each one can be represented by a state machine, and then the overall state…
DGM
  • 25,680
  • 6
  • 56
  • 79
8
votes
2 answers

AASM is not working with my rails 3 and ruby 1.8.7 ( undefined method `name' for nil:NilClass )

I'm using Rails 3.2.2, with aasm gem, I have Document model this way: class Document < ActiveRecord::Base include AASM aasm do state :unread, :initial => true state :read state :closed event :view do transitions :to =>…
Eqbal
  • 1,519
  • 2
  • 14
  • 23
7
votes
1 answer

How to set up a guard at the state level in AASM

Is there a way to define a guard (eg has_legs?) that is checked before entering a state (eg running) in any event? In the list of all possible callbacks there are guards for events and transitions, but not for events. I tried to do a conditional…
Victor
  • 20,476
  • 27
  • 76
  • 108
7
votes
5 answers

Getting list of states/events from a model that AASM

I successfully integrated the most recent AASM gem into an application, using it for the creation of a wizard. In my case I have a model order class Order < ActiveRecord::Base belongs_to :user has_one :billing_plan, :dependent => :destroy …
Jason Nerer
  • 391
  • 6
  • 18
7
votes
2 answers

Adding validations to rails aasm state

in state_machine I used to do state :cancelled do validates_presence_of :user end it would automatically cancel the transition if user was not present. How do we add similar validations to specific states in aasm?
Raz
  • 6,249
  • 4
  • 17
  • 17
7
votes
1 answer

AASM: Separating the state machine definition from the class definition

suppose I have this class (taken directly from the aasm documentation): class Job < ActiveRecord::Base include AASM aasm do state :sleeping, :initial => true state :running state :cleaning event :run do transitions :from…
Gnagno
  • 557
  • 6
  • 16
6
votes
1 answer

AASM: Transitions to a 2 different states depending on conditions

I am using AASM. Is it possible 2 different states depending on conditions For example: aasm_event :completes do transitions :to => condition? ? :complete : :terminate, :from => [:active] end the purpose of this is because I'm…
zetacu
  • 14,680
  • 1
  • 14
  • 22
6
votes
2 answers

Rails error handling with AASM state machine

I'm using the rubyist-aasm state machine for handling the different states in my Event object (event initialized, event discussed, event published, etc.). I added guards to prevent state changes when certain conditions aren't met. This all works…
Cimm
  • 4,341
  • 7
  • 36
  • 61
5
votes
3 answers

cancelling a sheduled Sidekiq job in Rails

Some Sidekiq jobs in my app are scheduled to change the state of a resource to cancelled unless a user responds within a certain timeframe. There is a lot of information about how to best accomplish this task, but none of it actually cancels the…
calyxofheld
  • 361
  • 1
  • 15
  • 35
5
votes
1 answer

Best Practices for using AASM in a Rails API Controller

We are using acts_as_state_machine (AASM) in our Rails app to control flow of models from one state to the next in a traditional finite state-machine. We are building out an API for our application, and as part of that we'd like to be able to…
Joel Hooks
  • 6,059
  • 3
  • 31
  • 37
1
2 3
8 9