Created
December 3, 2020 16:44
-
-
Save leastbad/fd33e2918eb37fcd6c30e593f20e7a1f to your computer and use it in GitHub Desktop.
Julian's multi-step validations state machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aasm do | |
state :invited, initial: true | |
state :identified | |
state :details_added | |
state :bank_details_added | |
state :completed | |
event :identify do | |
transitions from: :invited, to: :identified | |
end | |
event :add_details do | |
transitions from: :identified, to: :details_added | |
end | |
event :add_bank_details do | |
transitions from: :details_added, to: :bank_details_added | |
end | |
event :complete do | |
transitions from: :bank_details_added, to: :completed | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates :company_name, :address, :country, :zip, :city, | |
:trade_certificate, presence: true, on: :add_details | |
validates :terms_of_service, acceptance: true, on: :complete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= render 'devise/registrations/activation/step_1_identification' if @partner.invited? | |
= render 'devise/registrations/activation/step_2_details' if @partner.identified? | |
= render 'devise/registrations/activation/step_3_bank_account' if @partner.details_added? | |
= render 'devise/registrations/activation/step_4_acceptance' if @partner.bank_details_added? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://guides.rubyonrails.org/active_record_validations.html#grouping-conditional-validations