Skip to content

after_transition doesn't have previous state scoped #259

Description

@msxavi

Let's say we need to send an email after every state transition and the requirement is to include in this email subject: "Changed From: #{previous_state} TO: #{current_state}"

The way I currently do it:

  after_transition do |model, transition|
    previous_state = model.transitions.where(most_recent: false).last.to_state
    StateTransitionNotifier.new(previous_state, model.current_state).perform
  end

Why not having the "from" state scoped here? It would not be correct doing this on before_transition callback as something could go wrong, right? Even though, we could rely on validations, using before_transition would be semantically incorrect.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions