SlideShare a Scribd company logo
1 of 46
Ultra Light &
Maintainable
Wizards in Rails
Andy Maleh
VP of Engineering
BIG ASTRONAUT
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
EarlyShares Project Idea Submission
Wizard Example
Step 1 – Basic Info
Wizard Example
Step 2 – Details
Wizard Example
Step 3 – Document Content
Wizard Example
Step 4 – Preview
Wizard Example
Steps Done – Project Landing Page
Wizard Implementation
Goals
• Rails Server must persist progress on every step
o JS Client-Side Persistence is Out Of Scope
• REST
• MVC
• OO
• Non-Functional Requirements:
o Productivity
o Maintainability
o Performance
o Security
1001 Wizard
Implementations
1. One Controller Per Wizard Step
• Create a REST resource per wizard step
• One ActiveRecord with conditional validations
• Multiple Controllers
• Multiple sets of Views and Helpers
• Have each wizard step controller redirect to the
next one on create or update
1001 Wizard
Implementations
1. One Controller Per Wizard Step
Step 1
Controller
Step 2
Controller
Step 3
Controller
Step 4
Controller
Create &
Redirect to New
Create &
Redirect to New
Create &
Redirect to New
Step 1
ActiveRecord
1001 Wizard
Implementations
1. One Controller Per Wizard Step
o Critique
• Redundant code across controllers
o Repetitive redirect logic
o Redundant authentication logic
o Similar model loading logic
o Similar REST actions
• Tying database tables to presentation details
1001 Wizard
Implementations
2. 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
2. One Action Per Wizard Step
Controller
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 1
Presenter
Validation/Persistance
Adapter
Step 2
Presenter
Validation/Persistance
Adapter
Step 3
Presenter
Validation/Persistance
Adapter
Step 4
Presenter
Validation/Persistance Adapter
ActiveRecord
Create Step &
Redirect to New Ste
1001 Wizard
Implementations
2. One Action Per Wizard Step
o Critique
• Not RESTful
• Redundant code across actions
o Repetitive redirect logic
o Repetitive update logic
• Too much presenter management code
1001 Wizard
Implementations
3. Session Accumulation
o Create one ActiveRecord
o Have multiple Controllers or Actions accumulate wizard step data in the
session
o Have ActiveRecord in-memory conditional validations run on every step
o On the final step, create ActiveRecord running all validations
Step 1
Step 2
Step 3
Step 4
Accumulate
in Session
Accumulate
in Session
Accumulate
in Session
Create
ActiveRecord
1001 Wizard
Implementations
3. Session Accumulation
o Critique
• 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
4. Hidden Value Accumulation
o Same as session value accumulation except the controller manages data
coming from a request parameter
o Same pros and cons as Session Value Accumulation except that it has no
scalability implications
o NOTE: hidden value must be encrypted for security
1001 Wizard
Implementations
5. State Machine
o Create one ActiveRecord
o Make ActiveRecord a state machine managing steps:
• adding a step column
• add current_step, next_step, and prev_step methods
o Different view per step
o 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
5. State Machine
o Critique
• Puts presentation concerns in Model (breaks MVC)
o 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
o 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
1001. 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 Review
• Rails Server must persist progress on every step
o JS Client-Side Persistence is Out Of Scope
• REST
• MVC
• OO
• Non-Functional Requirements:
o Productivity
o Maintainability
o Performance
o Security
Ultra Light &
Maintainable Wizard
• Philosophy:
o A wizard is simply a builder of a model
Ultra Light &
Maintainable Wizard
• Philosophy:
o Every step is simply a partial data-view of the model
Ultra Light &
Maintainable Wizard
• Philosophy:
o REST resources are the model and model parts edited during a step.
Ultra Light &
Maintainable Wizard
• Philosophy:
o Models must manage validations without conditions by relying on step-
polymorphism
Ultra Light &
Maintainable Wizard
• Philosophy:
o Step view forms are maintained independently with no conditionals as
well
step1.html.erb
step2.html.erb
step3.html.erb
step4.html.erb
Ultra Light &
Maintainable Wizard
Model
Controller
Create
Show
Step 1 Presenter
Validations/Step Logic
Step 2 Presenter
Validations/Step Logic
Step 3 Presenter
Validations/Step Logic
Model
ActiveRecord
Core Validations
& Shared Logic
Step 4 Presenter
Validations/Step Logic
Update &
Redirect to Edit
Model Part
Controller
Edit
Update
Ultra Light &
Maintainable Wizard
• In a Nutshell:
o Model resource
o Nested model part resource
(e.g. /projects/project1/project_parts/basic_info)
• Step name serves as ID
• Contains validations and before/after hooks for stepping
o Controller for the model resource:
• Begins wizard by creating model ActiveRecord
• Shows produced model at the end of the wizard
o Controller for the model part resource:
• Every step represents an Edit action of a model part
• Every step submission represents an Update action of a model part
o View for model resource show page
o View for every model part presenter edit page
Ultra Light &
Maintainable Wizard
Routes
Ultra Light &
Maintainable Wizard
Model (main REST resource)
Ultra Light &
Maintainable Wizard
Step Sub-Models aka Model Parts
Ultra Light &
Maintainable Wizard
Project::BasicInfo Step Sub-Model
Ultra Light &
Maintainable Wizard
Project::BasicInfo Step Sub-Model (cont’d)
Ultra Light &
Maintainable Wizard
Project::Detail Step Sub-Model
Ultra Light &
Maintainable Wizard
ProjectsController
ProjectPartsController
Ultra Light &
Maintainable Wizard
ProjectPartsController (cont’d)
Ultra Light &
Maintainable Wizard
Views
Ultra Light &
Maintainable Wizard
View form template
Ultra Light &
Maintainable Wizard
Step View Template Example
Review
• Why Use A Wizard?
• Wizard Example
• Wizard Implementation Goals
• 1001 Wizard Implementations
• Ultra Light & Maintainable Wizard
github.com/AndyMaleh/u
ltra_light_wizard
Andy Maleh – VP of Engineering – Big Astronaut
• WEBSITE: http://www.bigastronaut.com
• BLOG: http://andymaleh.blogspot.com
• TWITTER: @AndyMaleh

More Related Content

What's hot

Splunk conf2014 - Using Selenium and Splunk for Transaction Monitoring Insight
Splunk conf2014 - Using Selenium and Splunk for Transaction Monitoring InsightSplunk conf2014 - Using Selenium and Splunk for Transaction Monitoring Insight
Splunk conf2014 - Using Selenium and Splunk for Transaction Monitoring InsightSplunk
 
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016Rafał Leszko
 
Continuous Delivery - Devoxx Morocco 2016
Continuous Delivery - Devoxx Morocco 2016Continuous Delivery - Devoxx Morocco 2016
Continuous Delivery - Devoxx Morocco 2016Rafał Leszko
 
Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaBaskar rao Dsn
 
[UC4] Version and Automate Everything
[UC4] Version and Automate Everything[UC4] Version and Automate Everything
[UC4] Version and Automate EverythingPerforce
 
How Gear4Music Went from 0-1000+ API Tests
How Gear4Music Went from 0-1000+ API TestsHow Gear4Music Went from 0-1000+ API Tests
How Gear4Music Went from 0-1000+ API TestsPostman
 
Introduction to GOCD - Amulya Sharma
Introduction to GOCD - Amulya SharmaIntroduction to GOCD - Amulya Sharma
Introduction to GOCD - Amulya SharmaAmulya Sharma
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await ExplainedJeremy Likness
 
Asp.net event handler
Asp.net event handlerAsp.net event handler
Asp.net event handlerSireesh K
 
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
 
Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!Atlassian
 
Salesforce Process builder Vs Workflows
Salesforce Process builder Vs WorkflowsSalesforce Process builder Vs Workflows
Salesforce Process builder Vs WorkflowsPrasanna Deshpande ☁
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsYakov Fain
 
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
 
Si fa presto a dire serverless
Si fa presto a dire serverlessSi fa presto a dire serverless
Si fa presto a dire serverlessAlessio Coser
 
Durable functions
Durable functionsDurable functions
Durable functionsToan Nguyen
 
Optimize your delivery and quality with the right release methodology and too...
Optimize your delivery and quality with the right release methodology and too...Optimize your delivery and quality with the right release methodology and too...
Optimize your delivery and quality with the right release methodology and too...DroidConTLV
 

What's hot (20)

Splunk conf2014 - Using Selenium and Splunk for Transaction Monitoring Insight
Splunk conf2014 - Using Selenium and Splunk for Transaction Monitoring InsightSplunk conf2014 - Using Selenium and Splunk for Transaction Monitoring Insight
Splunk conf2014 - Using Selenium and Splunk for Transaction Monitoring Insight
 
Supervise your Akka actors
Supervise your Akka actorsSupervise your Akka actors
Supervise your Akka actors
 
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016
 
Continuous Delivery - Devoxx Morocco 2016
Continuous Delivery - Devoxx Morocco 2016Continuous Delivery - Devoxx Morocco 2016
Continuous Delivery - Devoxx Morocco 2016
 
Azure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsaAzure Functions in Action #CodePaLOUsa
Azure Functions in Action #CodePaLOUsa
 
[UC4] Version and Automate Everything
[UC4] Version and Automate Everything[UC4] Version and Automate Everything
[UC4] Version and Automate Everything
 
How Gear4Music Went from 0-1000+ API Tests
How Gear4Music Went from 0-1000+ API TestsHow Gear4Music Went from 0-1000+ API Tests
How Gear4Music Went from 0-1000+ API Tests
 
Introduction to GOCD - Amulya Sharma
Introduction to GOCD - Amulya SharmaIntroduction to GOCD - Amulya Sharma
Introduction to GOCD - Amulya Sharma
 
C# Async/Await Explained
C# Async/Await ExplainedC# Async/Await Explained
C# Async/Await Explained
 
Asp.net event handler
Asp.net event handlerAsp.net event handler
Asp.net event handler
 
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
 
Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!Mock Servers - Fake All the Things!
Mock Servers - Fake All the Things!
 
Salesforce Process builder Vs Workflows
Salesforce Process builder Vs WorkflowsSalesforce Process builder Vs Workflows
Salesforce Process builder Vs Workflows
 
Using JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot appsUsing JHipster for generating Angular/Spring Boot apps
Using JHipster for generating Angular/Spring Boot apps
 
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
 
Si fa presto a dire serverless
Si fa presto a dire serverlessSi fa presto a dire serverless
Si fa presto a dire serverless
 
Durable functions
Durable functionsDurable functions
Durable functions
 
Monitoring your API
Monitoring your APIMonitoring your API
Monitoring your API
 
Optimize your delivery and quality with the right release methodology and too...
Optimize your delivery and quality with the right release methodology and too...Optimize your delivery and quality with the right release methodology and too...
Optimize your delivery and quality with the right release methodology and too...
 

Similar to Ultra Light and Maintainable Rails Wizards at RailsConf 2014

Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationStephen Fuqua
 
PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux Neotys
 
Automated Acceptance Testing Example
Automated Acceptance Testing ExampleAutomated Acceptance Testing Example
Automated Acceptance Testing ExampleHani Massoud
 
Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)CIVEL Benoit
 
Cerberus_Presentation1
Cerberus_Presentation1Cerberus_Presentation1
Cerberus_Presentation1CIVEL Benoit
 
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
 
Continuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases WeeklyContinuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases WeeklyRightScale
 
.NET microservices with Azure Service Fabric
.NET microservices with Azure Service Fabric.NET microservices with Azure Service Fabric
.NET microservices with Azure Service FabricDavide Benvegnù
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcdenemedeniz
 
Spring 1 day program
Spring 1 day programSpring 1 day program
Spring 1 day programMohit Kanwar
 
End to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJSEnd to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJSGil Fink
 
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum
 
Validation for APIs in Laravel 4
Validation for APIs in Laravel 4Validation for APIs in Laravel 4
Validation for APIs in Laravel 4Kirk Bushell
 
How kubernetes operators can rescue dev secops in midst of a pandemic updated
How kubernetes operators can rescue dev secops in midst of a pandemic updatedHow kubernetes operators can rescue dev secops in midst of a pandemic updated
How kubernetes operators can rescue dev secops in midst of a pandemic updatedShikha Srivastava
 
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
 
How Mature is Your Infrastructure?
How Mature is Your Infrastructure?How Mature is Your Infrastructure?
How Mature is Your Infrastructure?Gary Stafford
 

Similar to Ultra Light and Maintainable Rails Wizards at RailsConf 2014 (20)

Refactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test AutomationRefactoring Legacy Web Forms for Test Automation
Refactoring Legacy Web Forms for Test Automation
 
PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux PAC 2019 virtual Bruno Audoux
PAC 2019 virtual Bruno Audoux
 
Neoload
Neoload Neoload
Neoload
 
Automated Acceptance Testing Example
Automated Acceptance Testing ExampleAutomated Acceptance Testing Example
Automated Acceptance Testing Example
 
Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)Cerberus : Framework for Manual and Automated Testing (Web Application)
Cerberus : Framework for Manual and Automated Testing (Web Application)
 
Cerberus_Presentation1
Cerberus_Presentation1Cerberus_Presentation1
Cerberus_Presentation1
 
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
 
Continuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases WeeklyContinuous Delivery: How RightScale Releases Weekly
Continuous Delivery: How RightScale Releases Weekly
 
.NET microservices with Azure Service Fabric
.NET microservices with Azure Service Fabric.NET microservices with Azure Service Fabric
.NET microservices with Azure Service Fabric
 
Hanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvcHanselman lipton asp_connections_ams304_mvc
Hanselman lipton asp_connections_ams304_mvc
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
 
Spring 1 day program
Spring 1 day programSpring 1 day program
Spring 1 day program
 
End to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJSEnd to-End SPA Development Using ASP.NET and AngularJS
End to-End SPA Development Using ASP.NET and AngularJS
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan KuštInfinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
Infinum Android Talks #13 - Developing Android Apps Like Navy Seals by Ivan Kušt
 
Validation for APIs in Laravel 4
Validation for APIs in Laravel 4Validation for APIs in Laravel 4
Validation for APIs in Laravel 4
 
How kubernetes operators can rescue dev secops in midst of a pandemic updated
How kubernetes operators can rescue dev secops in midst of a pandemic updatedHow kubernetes operators can rescue dev secops in midst of a pandemic updated
How kubernetes operators can rescue dev secops in midst of a pandemic updated
 
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...
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
How Mature is Your Infrastructure?
How Mature is Your Infrastructure?How Mature is Your Infrastructure?
How Mature is Your Infrastructure?
 

More from 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
 

More from 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
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Ultra Light and Maintainable Rails Wizards at RailsConf 2014

  • 1. Ultra Light & Maintainable Wizards in Rails Andy Maleh VP of Engineering BIG ASTRONAUT
  • 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 – Basic Info
  • 8. Wizard Example Step 2 – Details
  • 9. Wizard Example Step 3 – Document Content
  • 10. Wizard Example Step 4 – Preview
  • 11. Wizard Example Steps Done – Project Landing Page
  • 12. Wizard Implementation Goals • Rails Server must persist progress on every step o JS Client-Side Persistence is Out Of Scope • REST • MVC • OO • Non-Functional Requirements: o Productivity o Maintainability o Performance o Security
  • 13. 1001 Wizard Implementations 1. One Controller Per Wizard Step • Create a REST resource per wizard step • One ActiveRecord with conditional validations • Multiple Controllers • Multiple sets of Views and Helpers • Have each wizard step controller redirect to the next one on create or update
  • 14. 1001 Wizard Implementations 1. One Controller Per Wizard Step Step 1 Controller Step 2 Controller Step 3 Controller Step 4 Controller Create & Redirect to New Create & Redirect to New Create & Redirect to New Step 1 ActiveRecord
  • 15. 1001 Wizard Implementations 1. One Controller Per Wizard Step o Critique • Redundant code across controllers o Repetitive redirect logic o Redundant authentication logic o Similar model loading logic o Similar REST actions • Tying database tables to presentation details
  • 16. 1001 Wizard Implementations 2. 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
  • 17. 1001 Wizard Implementations 2. One Action Per Wizard Step Controller 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 1 Presenter Validation/Persistance Adapter Step 2 Presenter Validation/Persistance Adapter Step 3 Presenter Validation/Persistance Adapter Step 4 Presenter Validation/Persistance Adapter ActiveRecord Create Step & Redirect to New Ste
  • 18. 1001 Wizard Implementations 2. One Action Per Wizard Step o Critique • Not RESTful • Redundant code across actions o Repetitive redirect logic o Repetitive update logic • Too much presenter management code
  • 19. 1001 Wizard Implementations 3. Session Accumulation o Create one ActiveRecord o Have multiple Controllers or Actions accumulate wizard step data in the session o Have ActiveRecord in-memory conditional validations run on every step o On the final step, create ActiveRecord running all validations Step 1 Step 2 Step 3 Step 4 Accumulate in Session Accumulate in Session Accumulate in Session Create ActiveRecord
  • 20. 1001 Wizard Implementations 3. Session Accumulation o Critique • 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
  • 21. 1001 Wizard Implementations 4. Hidden Value Accumulation o Same as session value accumulation except the controller manages data coming from a request parameter o Same pros and cons as Session Value Accumulation except that it has no scalability implications o NOTE: hidden value must be encrypted for security
  • 22. 1001 Wizard Implementations 5. State Machine o Create one ActiveRecord o Make ActiveRecord a state machine managing steps: • adding a step column • add current_step, next_step, and prev_step methods o Different view per step o Have single ActiveRecord manage each step validations by relying on conditional validations. For example: validate :phone, presence: true, if: lambda {current_step==“shipping”}
  • 23. 1001 Wizard Implementations 5. State Machine o Critique • Puts presentation concerns in Model (breaks MVC) o 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 o 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
  • 24. 1001 Wizard Implementations 1001. 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
  • 25. Wizard Implementation Goals Review • Rails Server must persist progress on every step o JS Client-Side Persistence is Out Of Scope • REST • MVC • OO • Non-Functional Requirements: o Productivity o Maintainability o Performance o Security
  • 26. Ultra Light & Maintainable Wizard • Philosophy: o A wizard is simply a builder of a model
  • 27. Ultra Light & Maintainable Wizard • Philosophy: o Every step is simply a partial data-view of the model
  • 28. Ultra Light & Maintainable Wizard • Philosophy: o REST resources are the model and model parts edited during a step.
  • 29. Ultra Light & Maintainable Wizard • Philosophy: o Models must manage validations without conditions by relying on step- polymorphism
  • 30. Ultra Light & Maintainable Wizard • Philosophy: o Step view forms are maintained independently with no conditionals as well step1.html.erb step2.html.erb step3.html.erb step4.html.erb
  • 31. Ultra Light & Maintainable Wizard Model Controller Create Show Step 1 Presenter Validations/Step Logic Step 2 Presenter Validations/Step Logic Step 3 Presenter Validations/Step Logic Model ActiveRecord Core Validations & Shared Logic Step 4 Presenter Validations/Step Logic Update & Redirect to Edit Model Part Controller Edit Update
  • 32. Ultra Light & Maintainable Wizard • In a Nutshell: o Model resource o Nested model part resource (e.g. /projects/project1/project_parts/basic_info) • Step name serves as ID • Contains validations and before/after hooks for stepping o Controller for the model resource: • Begins wizard by creating model ActiveRecord • Shows produced model at the end of the wizard o Controller for the model part resource: • Every step represents an Edit action of a model part • Every step submission represents an Update action of a model part o View for model resource show page o View for every model part presenter edit page
  • 33. Ultra Light & Maintainable Wizard Routes
  • 34. Ultra Light & Maintainable Wizard Model (main REST resource)
  • 35. Ultra Light & Maintainable Wizard Step Sub-Models aka Model Parts
  • 36. Ultra Light & Maintainable Wizard Project::BasicInfo Step Sub-Model
  • 37. Ultra Light & Maintainable Wizard Project::BasicInfo Step Sub-Model (cont’d)
  • 38. Ultra Light & Maintainable Wizard Project::Detail Step Sub-Model
  • 39. Ultra Light & Maintainable Wizard ProjectsController
  • 41. Ultra Light & Maintainable Wizard ProjectPartsController (cont’d)
  • 43. Ultra Light & Maintainable Wizard View form template
  • 44. Ultra Light & Maintainable Wizard Step View Template Example
  • 45. Review • Why Use A Wizard? • Wizard Example • Wizard Implementation Goals • 1001 Wizard Implementations • Ultra Light & Maintainable Wizard
  • 46. github.com/AndyMaleh/u ltra_light_wizard Andy Maleh – VP of Engineering – Big Astronaut • WEBSITE: http://www.bigastronaut.com • BLOG: http://andymaleh.blogspot.com • TWITTER: @AndyMaleh