Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

State Transitions Return true but do Nothing

#20

I have a class:

class Item < ActiveRecord::Base
  include AASM
  aasm_initial_state :available
  aasm_state :available
  aasm_state :in_use
  aasm_event(:check_out) do
    transitions :from => :available, :to => :in_use
  end
  aasm_event(:check_in) do
    transitions :from => :in_use, :to => :available
  end
end

This works:

i = Item.create!
i.write_attribute(:state, 'in_use')
# => "in_use"
i.save!
# => true
i.state
# => "in_use"

But this doesn't do anything:

i = Item.create!
i.check_out!
# => true
i.state
# => "available"

I'm on AASM 2.0.5 and Rails 2.3.2. I tried applying the patch for a (seemingly) related bug at http://www.pastie.org/444480 but that did nothing.

Reported by Gaius Centus Novus · June 22nd, 2009 @ 10:40 AM

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

  1. Gaius Centus Novus
    Gaius Centus Novus

    An oddity: after a state transition, read_attribute returns the correct value even though state doesn't:

    i = Item.create!
    i.check_out!
    i.state
    # => 'available'
    
    i.read_attribute(i.class.aasm_column)
    # => 'in_use'
    

    June 22nd, 2009 @ 11:54 AM

  2. Gaius Centus Novus
    Gaius Centus Novus

    The problem was that I was using alias_attribute instead of aasm_column:

    # wrong
    class Item
      include AASM
      alias_attribute :aasm_state, :state
    end
    
    # right
    class Item
      include AASM
      self.aasm_column :state
    end
    

    AASM wrote to ":aasm_state," which I assumed would write through, but didn't.

    This ticket can be closed.

    June 22nd, 2009 @ 11:59 AM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.