No commit activity in last 3 years
No release in over 3 years
Wizard Controller is an inheritable class to ease the creation of Wizards
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Wizard Controller¶ ↑

Wizard controller provides a base class (Inheriting from ActionController::Base) that provides a DSL for quickly making Wizards.

VERY IMPORTANT!!! DONT OVERRIDE INDEX! Doing so will break all functionality. WizardController works by defining an “index” method that does all the work. To start a wizard, go to the “index” method.

Setup and Configuration¶ ↑

Add the following gem configuration to config/environment.rb

config.gem "wizard_controller"

Ensure the following is present in config/routes.rb

map.connect ':controller/:action/:id'

… or explicitly map the routes you want to use.

Example Controller¶ ↑

class ExampleController < Codeprimate::Wizard::Base
  # Define the method names of the wixard steps
  define_steps :page_one, :page_two, :page_three

  # Specify where the Wizard should redirect upon completion.
  set_finish_path "http://www.example.com/go_here_when_done.html"

  # Ensure "index" is not defined!
  # def index
  # end

  def start
    # Create a "safe"  index method for this controller, and handle it appropriately
  end

  def foobar
    # You can define whatever actions you want.  WizardController doesnt get in the way.
  end

  def page_one
    # This is a regular action method. Create indiviual views for action methods.
  end

  def process_page_one
    # Place logic to handle any output from page one here.
    # No view will be shown for this
    #
    # Return true if your logic wants you to go to the next step
    # Return false if you want to return to the page_one view
    return true
  end  

  def page_two
    # Let's say this action/view is merely informative.
    # We will not supply a process method, and the user will always be able
    # to go to the next step
  end

  def page_three
    # Just another step method here
  end

  def process_page_three
    # Since this is the last step, if this process method returns true
    # the user will be redirected to the URL specified in the
    # "set_finish_path" declaration at the beginning of the Controller definition
  end
end

View Helper Methods¶ ↑

  • step_number(): Current step index.

  • total_steps(): Total Number of steps in the wizard.

  • step_completed(): Returns boolean, whether the step has been completed.

  • wizard_path(): Wizard index path. THIS SHOULD BE THE ACTION PATH OF ALL FORMS/VIEWS WITH A “process” action.

  • next_step_path(): URL to the next step.

  • previous_step_path(): URL to the previous step.

  • direct_step_path(): URL to a direct step. Example for step 3: direct_step_path(:id=>3). User will stay on the current step if they have not completed the one they are requesting.

  • reset_wizard_path(): URL to reset the Wizard.

  • abort_wizard_path(): URL to abort the Wizard.