SlideShare uma empresa Scribd logo
1 de 39
Ultra Light &
Maintainable Wizards in
Rails
Andy Maleh
President and Chief Journeyman
Soft Buzz
Overview
Why Use A Wizard?
Wizard Example
Wizard Implementation Goals
1001 Wizard Implementations

Ultra Light & Maintainable Wizard
Why Use A Wizard?
Avoid overwhelming user with a huge
form
Why Use A Wizard?
Simplify a workflow into multiple steps
Why Use A Wizard?
Help the user by providing guidance
Wizard Example
Event Registration Wizard
Wizard Example
Step 1 – Personal Info
Wizard Example
Step 2 – Background Info
Wizard Example
Step 3 – Review
Wizard Example
Step 4 – Payment
Wizard Example
Steps Done – Order Confirmation
Wizard Implementation Goals
REST
MVC
OO
Non-Functional Requirements:
Productivity
Maintainability
Performance
Security
1001 Wizard
Implementations
1. One Controller/ActiveRecord Per Wizard Step
•

Create a REST resource per wizard step
•
•
•

Multiple ActiveRecords with distinct
validations
Multiple Controllers
Multiple sets of Views and Helpers

•

Bind every wizard step form to corresponding
ActiveRecord

•

Have each wizard step controller redirect to
the next one on create or update
1001 Wizard
Implementations
1. One Controller/ActiveRecord Per Wizard Step
Step 1
ActiveRecord

Step 1
Controller

Step 2
ActiveRecord

Create &
Redirect to New
Step 2
Controller
Create &
Redirect to New

Step 3
ActiveRecord

Step 3
Controller

Step 4
ActiveRecord

Create &
Redirect to New
Step 4
Controller
1001 Wizard
Implementations
1. One Controller/ActiveRecord Per Wizard Step
Pros
Easy to understand and follow
RESTful
1001 Wizard
Implementations
1. One Controller/ActiveRecord Per Wizard Step
Cons
Redundant code across controllers
Repetitive redirect logic
Redundant authentication logic
Similar model loading logic
Similar REST actions

Tying database tables to presentation details
1001 Wizard
Implementations
1a. One Controller/Presenter Per Wizard Step
•

Create one ActiveRecord

•

Create a controller and ActiveModel presenter per
wizard step

•

Have each ActiveModel presenter manage its own
step validation logic

•

Bind every wizard step form to corresponding
ActiveModel presenter

•

Have each wizard step controller redirect to the
next one on create or update
1001 Wizard
Implementations
1a. One Controller/Presenter Per Wizard Step
Step 1
Controller

Step 1
Presenter

Step 2
Presenter

Create &
Redirect to New
Step 2
Controller
Create &
Redirect to New

Step 3
Presenter

Step 3
Controller

ActiveRecord
Step 4
Presenter

Create &
Redirect to New
Step 4
Controller
1001 Wizard
Implementations
1a. One Controller/Presenter Per Wizard Step
Pros
Easy to understand and follow
RESTful
Works with one ActiveRecord
1001 Wizard
Implementations
1a. One Controller/Presenter Per Wizard Step
Cons
Redundant code across controllers
Repetitive redirect logic
Redundant authentication logic
Similar model loading logic
Similar REST actions

Too much presenter validation/persistence
management code
1001 Wizard
Implementations
1b. One Action/Presenter Per Wizard Step
•

Create one ActiveRecord

•

Create one controller with a different new and create action
variation per wizard step
•

e.g. new_step1, create_step1, new_step2, create_step2, etc…

•

Create a different ActiveModel presenter per wizard step

•

Have each ActiveModel presenter manage its own step
validation logic

•

Bind every wizard step form to corresponding ActiveModel
presenter

•

Have each wizard step action redirect to the next one on create
1001 Wizard
Implementations
1b. One Action/Presenter Per Wizard Step
Step 1
Presenter
Validation/Persistance
Adapter

ActiveRecord

Create Step &
Redirect to New Ste

Controller

Step 2
Presenter
Validation/Persistance
Adapter
Step 3
Presenter
Validation/PersistanceAdapt
er

Step 1 New
Step 1 Create
Step 2 New
Step 2 Create
Step 3 New
Step 3 Create
Step 4 New
Step 4 Create

Step 4
Presenter
Validation/Persistance Adapter
1001 Wizard
Implementations
1b. One Action/Presenter Per Wizard Step
Pros
Easy to understand and follow
Works with one ActiveRecord
Lighter controller code
Reused controller hooks (e.g. authentication)
1001 Wizard
Implementations
1b. One Action/Presenter Per Wizard Step
Cons
Not RESTful
Redundant code across actions
Repetitive redirect logic
Repetitive update logic

Too much presenter management code
1001 Wizard
Implementations
2. Session Accumulation

Step 1

Create one ActiveRecord
Have multiple Controllers or Actions accumulate
wizard step data in the session
Have ActiveModel presenters handle
validation/forms
On the final step, create ActiveRecord running all
Create
validations
Step 3

Accumulate
in Session

Step 2

Accumulate
in Session

Accumulate
in Session

Step 4

ActiveRecor
d
1001 Wizard
Implementations
2. Session Accumulation
Pros
Works with one ActiveRecord
1001 Wizard
Implementations
2. Session Accumulation
Cons
Reliance on session has implications on scalability
Controller code more complex due to managing
session data storage
Validations defined twice, once per ActiveModel
presenters used for form validation and once in the
actual ActiveRecord
1001 Wizard
Implementations
3. Hidden Value Accumulation
Same as session value accumulation except the
controller manages data coming from a request
parameter
Same pros and cons as Session Value
Accumulation except that it has no scalability
implications
NOTE: hidden value must be encrypted for
security
1001 Wizard
Implementations
4. State Machine
Create one ActiveRecord
Make ActiveRecord a state machine managing steps:
adding a step column
add current_step, next_step, and prev_step methods

Different view per step
Have single ActiveRecord manage each step
validations by relying on conditional validations. For
example:
validate :phone,
presence: true,

if: lambda {current_step==“shipping”}
1001 Wizard
Implementations
4. State Machine
Pros
Works with one ActiveRecord
Simpler step management logic in one controller
1001 Wizard
Implementations
4. State Machine
Cons
Puts presentation concerns in Model (breaks MVC)
The state machine wizard must be a layer on top of
the Model. It has nothing to do with the business
model.

Stores an extra column in the database for purely
presentation-related reasons
Can be avoided with session storage of state, opening
a different can of worms (controller complexity)

More complexity in declaring validations due to
conditions and potentially overloading the Model
1001 Wizard
Implementations
5. Gems
Wizardry: state machine in model
Wicked: clean state machine in controller (better)
but no validation support beyond conditional
validation

Rails-Wizard-Generator: XML XML XML
Stepper: Nice support for steps in model and
controller
Wizard Implementation
Goals
REST
MVC
OO
Non-Functional Requirements:
Productivity
Maintainability
Performance
Security
Ultra Light & Maintainable
Wizard
Philosophy:
A wizard is simply a builder of a model
Every step is simply a partial data-view of the
model
REST resource is still the model itself and thus
must have a single controller
Models must manage validations without
conditions by relying on step-polymorphism
View forms are presented based on steppolymorphism
Ultra Light & Maintainable
Wizard
Details:
Create one main ActiveRecord model
Create “step submodels” subclassing the main model:
Each presents a partial view of the main model
Each has validations only for its step, thus no
conditionals
Each has before and after initialization for that step

Create a single controller:
It begins wizard by creating main ActiveRecord
Every step represents an Edit action of a “step
submodel”

Create a different view per step, each binding to “step
submodel” to ensure the right validations are triggered
Ultra Light & Maintainable
Wizard
Update &
Redirect to Edit
Step 1
ActiveRecord
Validations/Step Logic

Controller
Step 2
ActiveRecord
Validations/Step Logic
Step 3
ActiveRecord
Validations/Step Logic
ActiveRecord
Step 4
ActiveRecord
Validations/Step Logic

Create
Edit
Update
Ultra Light & Maintainable
Wizard
Code Review in Editor
Review
Why Use A Wizard?
Wizard Example
Wizard Implementation Goals
1001 Wizard Implementations

Ultra Light & Maintainable Wizard
Contact
Andy Maleh
BLOG: http://andymaleh.blogspot.com
TWITTER: @AndyMaleh
WEBSITE:http://www.softbuzz.ca

Mais conteúdo relacionado

Mais procurados

Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaBaskar rao Dsn
 
Avoiding integration hell
Avoiding integration hellAvoiding integration hell
Avoiding integration hellaaronbassett
 
Integration Testing as Validation and Monitoring
 Integration Testing as Validation and Monitoring Integration Testing as Validation and Monitoring
Integration Testing as Validation and MonitoringMelissa Benua
 
Asp.net event handler
Asp.net event handlerAsp.net event handler
Asp.net event handlerSireesh K
 
[UC4] Version and Automate Everything
[UC4] Version and Automate Everything[UC4] Version and Automate Everything
[UC4] Version and Automate EverythingPerforce
 
Developer day - AWS: Fast Environments = Fast Deployments
Developer day - AWS: Fast Environments = Fast DeploymentsDeveloper day - AWS: Fast Environments = Fast Deployments
Developer day - AWS: Fast Environments = Fast DeploymentsMatthew Cwalinski
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await ExplainedJeremy Likness
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...Postman
 
Using microsoft application insights to implement a build, measure, learn loop
Using microsoft application insights to implement a build, measure, learn loopUsing microsoft application insights to implement a build, measure, learn loop
Using microsoft application insights to implement a build, measure, learn loopMarcel de Vries
 
DRAKON Visual Language: Tutorial. Part 2
DRAKON Visual Language: Tutorial. Part 2DRAKON Visual Language: Tutorial. Part 2
DRAKON Visual Language: Tutorial. Part 2Stepan Mitkin
 
Introduce flux & react in practice
Introduce flux & react in practiceIntroduce flux & react in practice
Introduce flux & react in practiceHsuan Fu Lien
 
Durable functions
Durable functionsDurable functions
Durable functionsToan Nguyen
 
Fast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVCFast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVCAnkit Kashyap
 
SauceCon 2017: Testing @ the Speed of Concurrency
SauceCon 2017: Testing @ the Speed of ConcurrencySauceCon 2017: Testing @ the Speed of Concurrency
SauceCon 2017: Testing @ the Speed of ConcurrencySauce Labs
 
How to fix a bug in production - Rollout.io
How to fix a bug in production - Rollout.ioHow to fix a bug in production - Rollout.io
How to fix a bug in production - Rollout.ioRollout.io
 
Microstrategy Integrity Manager for QA tests automation
Microstrategy Integrity Manager for QA tests automationMicrostrategy Integrity Manager for QA tests automation
Microstrategy Integrity Manager for QA tests automationSlava Potapenko
 
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Startupfest
 

Mais procurados (20)

Supervise your Akka actors
Supervise your Akka actorsSupervise your Akka actors
Supervise your Akka actors
 
Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsa
 
Avoiding integration hell
Avoiding integration hellAvoiding integration hell
Avoiding integration hell
 
Integration Testing as Validation and Monitoring
 Integration Testing as Validation and Monitoring Integration Testing as Validation and Monitoring
Integration Testing as Validation and Monitoring
 
Asp.net event handler
Asp.net event handlerAsp.net event handler
Asp.net event handler
 
[UC4] Version and Automate Everything
[UC4] Version and Automate Everything[UC4] Version and Automate Everything
[UC4] Version and Automate Everything
 
Developer day - AWS: Fast Environments = Fast Deployments
Developer day - AWS: Fast Environments = Fast DeploymentsDeveloper day - AWS: Fast Environments = Fast Deployments
Developer day - AWS: Fast Environments = Fast Deployments
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
 
Using microsoft application insights to implement a build, measure, learn loop
Using microsoft application insights to implement a build, measure, learn loopUsing microsoft application insights to implement a build, measure, learn loop
Using microsoft application insights to implement a build, measure, learn loop
 
DRAKON Visual Language: Tutorial. Part 2
DRAKON Visual Language: Tutorial. Part 2DRAKON Visual Language: Tutorial. Part 2
DRAKON Visual Language: Tutorial. Part 2
 
Introduce flux & react in practice
Introduce flux & react in practiceIntroduce flux & react in practice
Introduce flux & react in practice
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Fast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVCFast Track introduction to ASP.NET MVC
Fast Track introduction to ASP.NET MVC
 
SauceCon 2017: Testing @ the Speed of Concurrency
SauceCon 2017: Testing @ the Speed of ConcurrencySauceCon 2017: Testing @ the Speed of Concurrency
SauceCon 2017: Testing @ the Speed of Concurrency
 
How to fix a bug in production - Rollout.io
How to fix a bug in production - Rollout.ioHow to fix a bug in production - Rollout.io
How to fix a bug in production - Rollout.io
 
TDD & VIPER
TDD & VIPERTDD & VIPER
TDD & VIPER
 
Microstrategy Integrity Manager for QA tests automation
Microstrategy Integrity Manager for QA tests automationMicrostrategy Integrity Manager for QA tests automation
Microstrategy Integrity Manager for QA tests automation
 
Monitoring your API
Monitoring your APIMonitoring your API
Monitoring your API
 
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
 

Semelhante a Ultra Light and Maintainable Wizards in Rails at Montreal.rb

Automated Acceptance Testing Example
Automated Acceptance Testing ExampleAutomated Acceptance Testing Example
Automated Acceptance Testing ExampleHani Massoud
 
VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...
VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...
VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...VMworld
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 
VMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
VMworld 2015: Automating Everything VMware with PowerCLI- Deep DiveVMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
VMworld 2015: Automating Everything VMware with PowerCLI- Deep DiveVMworld
 
OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016Stephen Fink
 
VMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery Manager
VMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery ManagerVMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery Manager
VMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery ManagerVMworld
 
vRealize Operation 7.5 What's new
vRealize Operation 7.5 What's newvRealize Operation 7.5 What's new
vRealize Operation 7.5 What's newKiss Tibor
 
Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2Salesforce Developers
 
Deep dive into new features in v realizeoperations 6.0
Deep dive into new features in v realizeoperations 6.0Deep dive into new features in v realizeoperations 6.0
Deep dive into new features in v realizeoperations 6.0solarisyougood
 
6 f13g formation-ibm-sterling-control-center-managing-control-center
6 f13g formation-ibm-sterling-control-center-managing-control-center6 f13g formation-ibm-sterling-control-center-managing-control-center
6 f13g formation-ibm-sterling-control-center-managing-control-centerCERTyou Formation
 
OpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integrationOpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integrationMichiel Kalkman
 
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...wwwally
 
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what...
Techdays 2013   managing your hybrid cloud datacenter with scom 2012 and what...Techdays 2013   managing your hybrid cloud datacenter with scom 2012 and what...
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what...CompuTrain. De IT opleider.
 

Semelhante a Ultra Light and Maintainable Wizards in Rails at Montreal.rb (20)

Automated Acceptance Testing Example
Automated Acceptance Testing ExampleAutomated Acceptance Testing Example
Automated Acceptance Testing Example
 
VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...
VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...
VMworld 2013: Part 2: How to Build a Self-Healing Data Center with vCenter Or...
 
Eclipse MVC
Eclipse MVCEclipse MVC
Eclipse MVC
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
ASP.NET MVC Extensibility
ASP.NET MVC ExtensibilityASP.NET MVC Extensibility
ASP.NET MVC Extensibility
 
VMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
VMworld 2015: Automating Everything VMware with PowerCLI- Deep DiveVMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
VMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
 
OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016OpenWhisk Under the Hood -- London Oct 16 2016
OpenWhisk Under the Hood -- London Oct 16 2016
 
VMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery Manager
VMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery ManagerVMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery Manager
VMworld 2013: Three Quirky Ways to Simplify DR with VMware Site Recovery Manager
 
vRealize Operation 7.5 What's new
vRealize Operation 7.5 What's newvRealize Operation 7.5 What's new
vRealize Operation 7.5 What's new
 
Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2Mastering the Lightning Framework - Part 2
Mastering the Lightning Framework - Part 2
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
10215 A 12
10215 A 1210215 A 12
10215 A 12
 
Asp.net mvc
Asp.net mvcAsp.net mvc
Asp.net mvc
 
Deep dive into new features in v realizeoperations 6.0
Deep dive into new features in v realizeoperations 6.0Deep dive into new features in v realizeoperations 6.0
Deep dive into new features in v realizeoperations 6.0
 
Cloud Networking
Cloud NetworkingCloud Networking
Cloud Networking
 
6 f13g formation-ibm-sterling-control-center-managing-control-center
6 f13g formation-ibm-sterling-control-center-managing-control-center6 f13g formation-ibm-sterling-control-center-managing-control-center
6 f13g formation-ibm-sterling-control-center-managing-control-center
 
OpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integrationOpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integration
 
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what’s...
 
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what...
Techdays 2013   managing your hybrid cloud datacenter with scom 2012 and what...Techdays 2013   managing your hybrid cloud datacenter with scom 2012 and what...
Techdays 2013 managing your hybrid cloud datacenter with scom 2012 and what...
 
Neoload
Neoload Neoload
Neoload
 

Mais de Andy Maleh

Fukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - OpalFukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - OpalAndy Maleh
 
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby MeetupBecoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby MeetupAndy Maleh
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...Andy Maleh
 
How I Built My Code Editor in Ruby
How I Built My Code Editor in RubyHow I Built My Code Editor in Ruby
How I Built My Code Editor in RubyAndy Maleh
 
RailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy MalehRailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy MalehAndy Maleh
 
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Andy Maleh
 
Software Craftsmanship VS Software Engineering
Software Craftsmanship VS Software EngineeringSoftware Craftsmanship VS Software Engineering
Software Craftsmanship VS Software EngineeringAndy Maleh
 
Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine PatternsAndy Maleh
 
Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)Andy Maleh
 
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Andy Maleh
 
Software Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for RubyistsSoftware Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for RubyistsAndy Maleh
 
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for RubyistsSoftware Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for RubyistsAndy Maleh
 
The Rails Engine That Could - In Motion
The Rails Engine That Could - In MotionThe Rails Engine That Could - In Motion
The Rails Engine That Could - In MotionAndy Maleh
 
The Rails Engine That Could
The Rails Engine That CouldThe Rails Engine That Could
The Rails Engine That CouldAndy Maleh
 
How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsAndy Maleh
 
Simplifying Desktop Development With Glimmer
Simplifying Desktop Development With GlimmerSimplifying Desktop Development With Glimmer
Simplifying Desktop Development With GlimmerAndy Maleh
 

Mais de Andy Maleh (16)

Fukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - OpalFukuoka Ruby Award 2023 - Opal
Fukuoka Ruby Award 2023 - Opal
 
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby MeetupBecoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
Becoming a SOC2 Ruby Shop - Montreal.rb November, 5, 2022 Ruby Meetup
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 
How I Built My Code Editor in Ruby
How I Built My Code Editor in RubyHow I Built My Code Editor in Ruby
How I Built My Code Editor in Ruby
 
RailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy MalehRailsConf 2014 Recap at Montreal.rb by Andy Maleh
RailsConf 2014 Recap at Montreal.rb by Andy Maleh
 
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
Revised Rails Engine Patterns for Montreal.rb meetup Oct 16, 2012
 
Software Craftsmanship VS Software Engineering
Software Craftsmanship VS Software EngineeringSoftware Craftsmanship VS Software Engineering
Software Craftsmanship VS Software Engineering
 
Rails Engine Patterns
Rails Engine PatternsRails Engine Patterns
Rails Engine Patterns
 
Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)Software Craftsmanship vs Software Engineering (Lightning Talk)
Software Craftsmanship vs Software Engineering (Lightning Talk)
 
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
Software Design Trilogy Part III - Domain Driven Design for Ruby on Rails App...
 
Software Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for RubyistsSoftware Design Trilogy Part II - Design Patterns for Rubyists
Software Design Trilogy Part II - Design Patterns for Rubyists
 
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for RubyistsSoftware Design Trilogy Part I - Responsibility Driven Design for Rubyists
Software Design Trilogy Part I - Responsibility Driven Design for Rubyists
 
The Rails Engine That Could - In Motion
The Rails Engine That Could - In MotionThe Rails Engine That Could - In Motion
The Rails Engine That Could - In Motion
 
The Rails Engine That Could
The Rails Engine That CouldThe Rails Engine That Could
The Rails Engine That Could
 
How I Learned To Apply Design Patterns
How I Learned To Apply Design PatternsHow I Learned To Apply Design Patterns
How I Learned To Apply Design Patterns
 
Simplifying Desktop Development With Glimmer
Simplifying Desktop Development With GlimmerSimplifying Desktop Development With Glimmer
Simplifying Desktop Development With Glimmer
 

Último

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Último (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Ultra Light and Maintainable Wizards in Rails at Montreal.rb

  • 1. Ultra Light & Maintainable Wizards in Rails Andy Maleh President and Chief Journeyman Soft Buzz
  • 2. Overview Why Use A Wizard? Wizard Example Wizard Implementation Goals 1001 Wizard Implementations Ultra Light & Maintainable Wizard
  • 3. Why Use A Wizard? Avoid overwhelming user with a huge form
  • 4. Why Use A Wizard? Simplify a workflow into multiple steps
  • 5. Why Use A Wizard? Help the user by providing guidance
  • 7. Wizard Example Step 1 – Personal Info
  • 8. Wizard Example Step 2 – Background Info
  • 10. Wizard Example Step 4 – Payment
  • 11. Wizard Example Steps Done – Order Confirmation
  • 12. Wizard Implementation Goals REST MVC OO Non-Functional Requirements: Productivity Maintainability Performance Security
  • 13. 1001 Wizard Implementations 1. One Controller/ActiveRecord Per Wizard Step • Create a REST resource per wizard step • • • Multiple ActiveRecords with distinct validations Multiple Controllers Multiple sets of Views and Helpers • Bind every wizard step form to corresponding ActiveRecord • Have each wizard step controller redirect to the next one on create or update
  • 14. 1001 Wizard Implementations 1. One Controller/ActiveRecord Per Wizard Step Step 1 ActiveRecord Step 1 Controller Step 2 ActiveRecord Create & Redirect to New Step 2 Controller Create & Redirect to New Step 3 ActiveRecord Step 3 Controller Step 4 ActiveRecord Create & Redirect to New Step 4 Controller
  • 15. 1001 Wizard Implementations 1. One Controller/ActiveRecord Per Wizard Step Pros Easy to understand and follow RESTful
  • 16. 1001 Wizard Implementations 1. One Controller/ActiveRecord Per Wizard Step Cons Redundant code across controllers Repetitive redirect logic Redundant authentication logic Similar model loading logic Similar REST actions Tying database tables to presentation details
  • 17. 1001 Wizard Implementations 1a. One Controller/Presenter Per Wizard Step • Create one ActiveRecord • Create a controller and ActiveModel presenter per wizard step • Have each ActiveModel presenter manage its own step validation logic • Bind every wizard step form to corresponding ActiveModel presenter • Have each wizard step controller redirect to the next one on create or update
  • 18. 1001 Wizard Implementations 1a. One Controller/Presenter Per Wizard Step Step 1 Controller Step 1 Presenter Step 2 Presenter Create & Redirect to New Step 2 Controller Create & Redirect to New Step 3 Presenter Step 3 Controller ActiveRecord Step 4 Presenter Create & Redirect to New Step 4 Controller
  • 19. 1001 Wizard Implementations 1a. One Controller/Presenter Per Wizard Step Pros Easy to understand and follow RESTful Works with one ActiveRecord
  • 20. 1001 Wizard Implementations 1a. One Controller/Presenter Per Wizard Step Cons Redundant code across controllers Repetitive redirect logic Redundant authentication logic Similar model loading logic Similar REST actions Too much presenter validation/persistence management code
  • 21. 1001 Wizard Implementations 1b. One Action/Presenter Per Wizard Step • Create one ActiveRecord • Create one controller with a different new and create action variation per wizard step • e.g. new_step1, create_step1, new_step2, create_step2, etc… • Create a different ActiveModel presenter per wizard step • Have each ActiveModel presenter manage its own step validation logic • Bind every wizard step form to corresponding ActiveModel presenter • Have each wizard step action redirect to the next one on create
  • 22. 1001 Wizard Implementations 1b. One Action/Presenter Per Wizard Step Step 1 Presenter Validation/Persistance Adapter ActiveRecord Create Step & Redirect to New Ste Controller Step 2 Presenter Validation/Persistance Adapter Step 3 Presenter Validation/PersistanceAdapt er Step 1 New Step 1 Create Step 2 New Step 2 Create Step 3 New Step 3 Create Step 4 New Step 4 Create Step 4 Presenter Validation/Persistance Adapter
  • 23. 1001 Wizard Implementations 1b. One Action/Presenter Per Wizard Step Pros Easy to understand and follow Works with one ActiveRecord Lighter controller code Reused controller hooks (e.g. authentication)
  • 24. 1001 Wizard Implementations 1b. One Action/Presenter Per Wizard Step Cons Not RESTful Redundant code across actions Repetitive redirect logic Repetitive update logic Too much presenter management code
  • 25. 1001 Wizard Implementations 2. Session Accumulation Step 1 Create one ActiveRecord Have multiple Controllers or Actions accumulate wizard step data in the session Have ActiveModel presenters handle validation/forms On the final step, create ActiveRecord running all Create validations Step 3 Accumulate in Session Step 2 Accumulate in Session Accumulate in Session Step 4 ActiveRecor d
  • 26. 1001 Wizard Implementations 2. Session Accumulation Pros Works with one ActiveRecord
  • 27. 1001 Wizard Implementations 2. Session Accumulation Cons Reliance on session has implications on scalability Controller code more complex due to managing session data storage Validations defined twice, once per ActiveModel presenters used for form validation and once in the actual ActiveRecord
  • 28. 1001 Wizard Implementations 3. Hidden Value Accumulation Same as session value accumulation except the controller manages data coming from a request parameter Same pros and cons as Session Value Accumulation except that it has no scalability implications NOTE: hidden value must be encrypted for security
  • 29. 1001 Wizard Implementations 4. State Machine Create one ActiveRecord Make ActiveRecord a state machine managing steps: adding a step column add current_step, next_step, and prev_step methods Different view per step Have single ActiveRecord manage each step validations by relying on conditional validations. For example: validate :phone, presence: true, if: lambda {current_step==“shipping”}
  • 30. 1001 Wizard Implementations 4. State Machine Pros Works with one ActiveRecord Simpler step management logic in one controller
  • 31. 1001 Wizard Implementations 4. State Machine Cons Puts presentation concerns in Model (breaks MVC) The state machine wizard must be a layer on top of the Model. It has nothing to do with the business model. Stores an extra column in the database for purely presentation-related reasons Can be avoided with session storage of state, opening a different can of worms (controller complexity) More complexity in declaring validations due to conditions and potentially overloading the Model
  • 32. 1001 Wizard Implementations 5. Gems Wizardry: state machine in model Wicked: clean state machine in controller (better) but no validation support beyond conditional validation Rails-Wizard-Generator: XML XML XML Stepper: Nice support for steps in model and controller
  • 34. Ultra Light & Maintainable Wizard Philosophy: A wizard is simply a builder of a model Every step is simply a partial data-view of the model REST resource is still the model itself and thus must have a single controller Models must manage validations without conditions by relying on step-polymorphism View forms are presented based on steppolymorphism
  • 35. Ultra Light & Maintainable Wizard Details: Create one main ActiveRecord model Create “step submodels” subclassing the main model: Each presents a partial view of the main model Each has validations only for its step, thus no conditionals Each has before and after initialization for that step Create a single controller: It begins wizard by creating main ActiveRecord Every step represents an Edit action of a “step submodel” Create a different view per step, each binding to “step submodel” to ensure the right validations are triggered
  • 36. Ultra Light & Maintainable Wizard Update & Redirect to Edit Step 1 ActiveRecord Validations/Step Logic Controller Step 2 ActiveRecord Validations/Step Logic Step 3 ActiveRecord Validations/Step Logic ActiveRecord Step 4 ActiveRecord Validations/Step Logic Create Edit Update
  • 37. Ultra Light & Maintainable Wizard Code Review in Editor
  • 38. Review Why Use A Wizard? Wizard Example Wizard Implementation Goals 1001 Wizard Implementations Ultra Light & Maintainable Wizard
  • 39. Contact Andy Maleh BLOG: http://andymaleh.blogspot.com TWITTER: @AndyMaleh WEBSITE:http://www.softbuzz.ca