Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aasm.current_event incorrectly yields nil when calling aasm.fire!(:event) #551

Closed
jaybloke opened this issue Apr 18, 2018 · 1 comment · Fixed by #638
Closed

aasm.current_event incorrectly yields nil when calling aasm.fire!(:event) #551

jaybloke opened this issue Apr 18, 2018 · 1 comment · Fixed by #638

Comments

@jaybloke
Copy link

jaybloke commented Apr 18, 2018

Given the following code excerpt:

aasm column :state do

  state :unkown, initial: true
  state :matched

  event :match do
    transitions from: :unknown, to: matched, after: :matched_event
  end

  def matched_event
    puts aasm.current_event  # yields nil if triggered with aasm.fire!(:match)
  end

end

aasm.match!                # => Correct, aasm.current_event yields 'match!'
aasm.fire!(:match)         # => Incorrect, aasm.current_event yields nil

Would be nice to get this fixed, as my controllers are beginning to look a lot like hackery (i have 30+ transitions) and have had to resort to this less than elegant code...

def update
  ...
  if model.respond_to?("may_#{params[:event]}?') && model.send("may_#{params[:event]}?")
    model.send("#{params[:event]}!")
  end
  ...
end
@anilmaurya
Copy link
Member

@jaybloke Looks like you encountered a bug .

A PR to fix this issue is much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants