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
0
votes
1 answer

Does the aasm state machine def need to be loaded once or many times for model class?

For a model class with AASM state machine, there is following def in the model class: class Job include AASM aasm do state :sleeping, :initial => true, :before_enter => :do_something state :running state :finished ...... end My…
user938363
  • 9,990
  • 38
  • 137
  • 303
0
votes
1 answer

statemachine state is always returning the last state instead of initial

I am trying to use aasm state machine for going from one state to another. But the issue is that the statemachine is moving through all states without calling. Here is the code am using include AASM aasm column: 'state' do state :pending,…
Abhilash
  • 2,864
  • 3
  • 33
  • 67
0
votes
0 answers

Can one state appear in multiple state machine with AASM?

Gem AASM supports multiple state machine per class with verion 4.3 or above. A unique state machine selector is used for each state machine in one class. Can one state appear in multiple state machine? Here is an example. The state walking appears…
user938363
  • 9,990
  • 38
  • 137
  • 303
0
votes
1 answer

Refactoring before_filters in Controller

I'm working on a rails app that has a whole bunch of before filters in the users_controller which look up user's stateful roles provided by Acts as State Machine. They look something like this: class UsersController <…
btw
  • 7,006
  • 9
  • 40
  • 40
0
votes
1 answer

Before callback doesn't work in AASM/Ruby

I'm trying to work on a finite state machine with AASM in Ruby. This is a part of my code: event :Orthography, :before => :to_lowercase do puts "Check Orthography" transitions :from => :Initialized, :to => :UniquenessChecked end event…
Jeroen Steen
  • 531
  • 8
  • 22
0
votes
1 answer

Use initialized variable in other methods with AASM

I'm trying to use a variable t in a other method, passed in initialize. This is my class for Term: class Term include AASM attr_accessor :t def initialize(term) @t = term puts self.t end aasm do state :Initialized, :initial…
Jeroen Steen
  • 531
  • 8
  • 22
0
votes
1 answer

How to pass a parameter to new/init in AASM gem

I'm trying to make a finite state machine chain with AASM gem. I want to check if a string is unique (not existing in the database). I wrote: require 'rubygems' require 'aasm' class Term include AASM aasm do state :Beginning, :initial =>…
Jeroen Steen
  • 531
  • 8
  • 22
0
votes
1 answer

Aasm Gem Passing params into Event

I am trying to pass parameters into my event using the aasm ruby gem and rails. However, whenever I try to follow the example in the documentation, I get the error Wrong number of arguments. Expected 0, got 2.. What am I doing wrong? Code is…
derigible
  • 964
  • 5
  • 15
  • 32
0
votes
1 answer

what does mean's aasm column in rails

I am new in rails and I am doing one project which has this code aasm_column :status aasm do state :unregistered, initial: true state :pending, enter: :enter_pending_state state :activated, enter: :enter_activated_state state…
Harman
  • 1,703
  • 5
  • 22
  • 40
0
votes
1 answer

Error when using eval to execute aasm block

We put the whole aasm block in string and eval it in payment_request model. Here is the def: class PaymentRequest < :ActiveRecord::Base include AASM def self.load_wf_spec(wf_spec, wf_def_name) eval("aasm(:#{wf_def_name}) :column =>…
user938363
  • 9,990
  • 38
  • 137
  • 303
0
votes
1 answer

Rails AASM helper for links for which state it may go to. Prefix to method call

In AASM you can call the may_run? as in the example code in the AASM. object: class Job include AASM aasm do state :sleeping, :initial => true state :running, :cleaning event :run do transitions :from => :sleeping, :to =>…
DogEatDog
  • 2,899
  • 2
  • 36
  • 65
0
votes
1 answer

Thread safe of state machine gems in multi-tenant Rail app

There are a few popular Ruby state machine gems such as geekq/workflow and aasm. Are they thread safe in multi-tenant Rails 4.2 application? I am using geekq/workflow which defines process definition on model class as class method. This makes me…
user938363
  • 9,990
  • 38
  • 137
  • 303
0
votes
1 answer

Callbacks in aasm gem and ActionMailer

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…
Martin
  • 4,042
  • 2
  • 19
  • 29
0
votes
2 answers

How to make a generic callback for any "event" in AASM

I have a State Machine, in a Rails app (with ActiveRecord), defined with AASM and it has a lot of callbacks. Some of these callbacks contain repeated code. E.g, on every state change, we need to build and save a record and send a mail. event…
berkes
  • 26,996
  • 27
  • 115
  • 206
0
votes
1 answer

How to pass args passed to an event to the error block with aasm?

My event is defined this way: event :share, after: :inc_in_path_share do transitions from: :bucketed, to: :shared error do |e| inc_share(message, tags) end end and I call it my_instance.share(message, tags). If the…
yutu
  • 109
  • 1
  • 5
1 2 3
8
9