in state_machine I used to do
state :cancelled do
  validates_presence_of :user
end
it would automatically cancel the transition if user was not present.
How do we add similar validations to specific states in aasm?
I can offer 2 options:
the first:
validates_presence_of :sex, :name, :surname, if: -> { state == 'personal' }
the second
event :fill_personal do
  before do
    instance_eval do
      validates_presence_of :sex, :name, :surname
    end
  end
  transitions from: :empty, to: :personal
end
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With