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
132 questions
2
votes
0 answers

Undefined method `aasm_state' for model Order Did you mean? aasm_state=

Rspec-rails tests started to fail after adding Aasm gem. All basic set ups are done. Migration with adding aasm_state column. Adding state to the Order model. Test log: Searching book Visitor searches books by title Failure/Error: order =…
StanisLove Sid
  • 322
  • 3
  • 9
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
  • 32,933
  • 55
  • 189
  • 380
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,641
  • 9
  • 59
  • 111
2
votes
3 answers

Rails AASM; How to do some action if the specific transition is occured

I use state machine gem called AASM on rails. There are an event which has two types of transitions. Three three types of state state pending state past_due state paid pending can be changed into paid past_due can be changed into paid event :pay…
Toshi
  • 6,012
  • 8
  • 35
  • 58
2
votes
3 answers

NoMethodError (undefined method `aasm_state') when saving a record

When saving payment request, there is an error popping up: NoMethodError (undefined method `aasm_state' for #): activemodel (4.2.0) lib/active_model/attribute_methods.rb:433:in `method_missing' …
user938363
  • 9,990
  • 38
  • 137
  • 303
2
votes
1 answer

Testing aasm state transitions with rspec

I'm using aasm gem to handle state transitions in my project. I have a simple model that looks like this: class TransferPostingBid < ActiveRecord::Base include AASM aasm :status do state :offered, initial: true state…
Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133
2
votes
1 answer

AASM Adding callbacks in a child class

Is there a way to add callbacks in a child model when AASM is defined in a parent model? class Parent include AASM aasm do state :initialised, :initial => true state :filled_out state :authorised event :fill_out do …
Reid
  • 41
  • 1
  • 5
2
votes
1 answer

How to call ActionMailer method in aasm callback?

Im learning ruby on rails and have a trouble with aasm callbacks and actionmailer. I have a hotels model. Heres a code: class Hotel < ActiveRecord::Base include AASM scope :approved_hotels, -> { where(aasm_state: "approved") } has_many…
2
votes
1 answer

delayed_job on ActiveRecord model with AASM - failing method error swallowed, throws "wrong number of arguments" instead

In my Rails 4 app, I have an ActiveRecord model with an AASM column. When I use a failing method with delayed_job_active_record, it swallows the error and throws something else to do with AASM. class MyModel < ActiveRecord::Base include AASM …
iftheshoefritz
  • 5,829
  • 2
  • 34
  • 41
2
votes
0 answers

AASM: guard method being called twice

While testing (Rspec) my state transitions using aasm I am noticing that all of my :guard methods are being called twice. For example: event :process_shipping_label do transitions :from => :label_generated, :to => :label_sent, :guard =>…
sfkaos
  • 205
  • 4
  • 10
2
votes
1 answer

How do I avoid duplication of code using AASM?

So I have in my project multiple models where many of them have an activate and deactivate function, which I manage using AASM aasm column: 'status' do state :active, :initial => true state :inactive event :deactivate do transitions :from…
Sherwyn Goh
  • 1,352
  • 1
  • 10
  • 19
2
votes
5 answers

Ruby on rails AASM Change transition on button click

My question is very simple: how can I change aasm transitions on button click? What should I put in my view? I have two buttons: Approve and Reject. My states look like this: aasm :column => 'state' do state :pending, :initial => true …
Al17
  • 431
  • 7
  • 20
2
votes
1 answer

Is there a way to keep history of states with aasm gem?

I am wondering if this gem provides a way to keep history of states. I probably can do this by adding a callback to each event but I am wondering what other people think about this approach.
denniss
  • 17,229
  • 26
  • 92
  • 141
2
votes
4 answers

Tool to generate state transition diagram for acts_as_state_machine

The ruby gem acts_as_state_machine can be super helpful for modeling object lifecycles within a flexible finite state machine framework. But I often find myself wanting a visual representation of the state transitions. Is there a tool to generate an…
pje
  • 21,801
  • 10
  • 54
  • 70
2
votes
2 answers

Register callback for all transitions in AASM?

There are 2 methods I want to call after every state transition. Right now I'm doing: aasm_event :nominate_for_publishing, :before => [:set_state_last_updated_by, :set_state_updated_at] do transitions :to => :under_review, :from =>…
Tom Lehman
  • 85,973
  • 71
  • 200
  • 272
1 2
3
8 9