aasm

ruby on rails state machines

I'm looking to implement a state machine to manage a user moving through a series of steps over an extended period of time (weeks) with emails and then they interact with the app. I've looked at a couple of AASM plugins and forks (it seems like this plugin space has become a bit chaotic) and am curious what people would recommend. I sa...

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 < ApplicationController before_filter :not_logged_in_required, :only => [:new, :create] before_filter :find_user_or_curre...

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. ...

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 updated. But a save isn't done on transitions.) I can't find much useful documentation ...

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 transition? ...

AASM Gem broken by Rails 2.3.2?

Has anyone had any problems using the AASM state machine Gem with Rails 2.3.2? It was working fine for me but is now giving a NoMethodError: NoMethodError (undefined method `state' for #<Comment:0x25cb8ac>): /usr/local/lib/ruby/gems/1.8/gems/rubyist-aasm-2.0.5/lib/persistence/active_record_persistence.rb:231:in `send' /usr/local/lib...

How do you override :set_initial_state from AASM when testing with Factory Girl factories?

Update Answered below. In case the linked site disappears, you can use mocha to stub the initial state and prevent overwriting as in ... require 'mocha' class OrderTest < ActiveSupport::TestCase def setup Order.any_instance.stubs(:set_initial_state) @order = Factory(:order, :state => "other_state") end ... end Origina...

Multiple counter cache columns with aasm

I am looking for a way to cache the number of each state. I have done counter caching before, but is there a way to create multiple counter_cache columns for each state and keep them updated or should I look elsewhere for caching these values. aasm_column :state aasm_initial_state :unopened aasm_state :unopened aasm_state :contacted a...

How can I access a collection of acts_as_state_machine states for a particular rails model?

Is it possible to access the collection of states for the given model: class Conversation include AASM aasm_initial_state :unread aasm_state :unread aasm_state :read aasm_state :closed aasm_event :view do transitions :to => :read, :from => [:unread] end aasm_event :close do transitions :to => :closed, :from => [:read, :unrea...

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 => [:work_in_progress] end aasm_event :publish, :before => [:set_state_last_updated_by, :set_state...

Best way to represent who changed the state of an object and when? (AASM)

Right now I'm storing the user who last updated the state of my model in the state_last_updated_by_id field and the time the state was last updated in the state_updated_at field. Then I define methods like this: def published_at return unless state == 'published' state_updated_at end def published_by return unless sta...

Can I make AASM run a specific method on event fail?

Is there a nice way to tell AASM that if an exception is raised while processing any assm_event I want that error to be caught by a specific block of code? eg currently I do something like assm_state :state_1 assm_state :state_2, :before_enter => :validate_something assm_state :failed assm_event :something_risky do transition :fro...

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 fine but it doesn't show any errors when a state change was rejected by the guard. Any idea...

rails state_machine pattern for credit card processing

I'm using the rails state_machine plugin (looks better than aasm) - it looks great - however, I've implemented it for a credit card processing system I wrote and it looks a bit strange... the code looks very un-DRY... I wonder if anyone can cast a quick eye over it and let me know what they think. In particular, to me the bits that does...

Hooking Observers with Events

Hi, We are using AASM in quite a few of our models, but we're looking at simplifying a bit the models. One of the things we'd like to do is to move all the Notification stuff out of the models and into Observers. So considering: class ClarificationRequest < ActiveRecord::Base include AASM aasm_initial_state :open # States aa...

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 of the registration might depend on the state of the others. Can aasm handle this? Any ...

Getting list of states/events from a model that AASM

Hi, 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 named_scope :with_user, ..... <snip> include AASM aasm_column :aasm_state aasm...