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
5
votes
3 answers

aasm after callback with argument

I'm using the aasm (formerly acts_as_state_machine) gem in my rails 4 application. I have something like this on my Post model ... aasm column: :state do state :pending_approval, initial: true state :active state :pending_removal …
Kyle Decot
  • 19,418
  • 35
  • 132
  • 245
4
votes
2 answers

AASM guarded by current_user

Is it possible to set up guards with AASM that control event access by user role? This seems like a fairly common use case, but I can't find a well agreed upon answer. Many people seem to suggest keeping the permission logic in the controllers,…
Jake Haller-Roby
  • 5,998
  • 1
  • 16
  • 29
4
votes
2 answers

How to add a default AASM state to existing model

I have an existing model in rails and I want to add AASM states to it. From my understanding, I should add a state column to my database through migrations first and then add some states to my rails model. How do I set a default state value…
Masha
  • 277
  • 1
  • 5
  • 17
3
votes
2 answers

Dynamically set initial state with aasm gem

I've an ActiveRecord model. I'd like to set an initial state depending on its attributes at the initialization. Here is my condition: self.expected_delivery_date.blank? ? :in_preparation : :waiting Is there a way to do that? Is it a bad idea?
Camille
  • 678
  • 6
  • 23
3
votes
1 answer

How to return a value on aasm event?

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 …
Vignesh
  • 548
  • 5
  • 15
3
votes
1 answer

What's the best way to automatically change state in AASM

I've been using AASM to make state machines in my current project and was wondering what's the best way to automatically call events and proceed to the next state? I am considering 2 ways of doing this: Setup a background job to periodically check…
Maxim Fedotov
  • 1,281
  • 1
  • 18
  • 35
3
votes
1 answer

How to set after callback for specific transition only in aasm?

I have 2 events: event :event1, after: :event2! do transitions to: :state2, from: :state1, guard: proc {some func} transitions to: :state3, from: :state1 end event :event2 do transitions to: :state3, from: state2, guard: proc {some…
3
votes
3 answers

Check if state is past another state in aasm?

Suppose there is an object with 4 states :new :in_process :done :verified There is also a method that should only be executed when the object is in a state greater than :in_process How do I go about doing this check? I thought it might be something…
2
votes
3 answers

How to tell AASM to igonore an event if that event is not applicable for the current state (a transition is not defined)?

I am using AASM. I have an event defined with a transition. It works if the event is raised and the model is in :from state. However it throws InValidTransition exception if the model is in any other state. aasm_state :first aasm_sate …
2
votes
2 answers

What is the best way to halt a transition with AASM

When a method being called in the success or enter phases of a state transition throw errors, what is the best way to catch this and ensure that the state reverts back to the previous state. I'm using the AASM gem.
MatthewFord
  • 2,889
  • 2
  • 18
  • 32
2
votes
1 answer

ActiveRecord where query not working for attributes but select method is

What explains this bizarre behavior? work_state is an state attribute derived from aasm gem, but I don't have trouble querying this with other models... MaintenanceOrder.all.select { |m| m.work_state == "pending_work" }.size =>…
james
  • 3,361
  • 5
  • 37
  • 83
2
votes
0 answers

nil state in aasm rails

There are two parts to my problem. how can i define nil as the initial state of any state machine? how can i transition any state to nil? if we do something like this then it saves "nil" as value not NULL, aasm(:aasm_state, column: :status) do …
2
votes
1 answer

How do I implement aasm in Rails 3 for what I want it to do?

I am a Rails n00b and have been advised that in order for me to keep track of the status of my user's accounts (i.e. paid, unpaid (and therefore disabled), free trial, etc.) I should use an 'AASM' gem. So I found one that seems to be the most…
marcamillion
  • 29,563
  • 49
  • 161
  • 337
2
votes
1 answer

AASM state machine exception handling example?

I'm currently working on a class, which is basically doing following: model gets created fetches data (event "get_things!") if exception happens, state should become "failed" if success, state should be "finished" I try to implement it as…
BvuRVKyUVlViVIc7
  • 11,200
  • 8
  • 55
  • 105
2
votes
2 answers

NameError: uninitialized constant Order::AASM

I am implement a order system with AASM, but when I use rails c to check the function, but something wrong happen. NameError: uninitialized constant Order::AASM There is gem 'aasm' in the Gemfile. I have searched Google and StackOverflow with…
张泽栋
  • 163
  • 2
  • 12
1
2
3
8 9