derigible
derigible

Reputation: 964

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 below:

class Foo < ActiveRecord::Base
  include AASM

  aasm column: :status do
    state :stopped, initial: true
    # TODO: if post fails, should this remain in_progress?
    state :running

    event :run, aasm_fire_event: :do_something do
      transitions from: :stopped, to: :running
    end
  end

  def do_something(list_of_things)
    .... #stuff here
  end
end

and then the calling code

foo = Foo.new
foo.run(:running, [param1, param2])    

This seems to follow the example, but I can't get it to work. Any help would be appreciated.

Upvotes: 0

Views: 1102

Answers (1)

derigible
derigible

Reputation: 964

For any who stumble upon this problem, if you have other callbacks on your event or on the old_state or new_state that will get called on the event, the above pattern will try to apply the parameters to all of the callbacks. This is what was happening to me, so I solved the problem by allowing the args to be passed on those callbacks and then not doing anything with them.

Upvotes: 0

Related Questions