Creating Flow Controllers

To create an ActionFlow controller, you must subclass the ActionFlow::Base ruby class.

class MyController < ActionFlow::Base
 
  def initialize
 
    # Add your mapping here
 
  end
 
  # Add your step implementations here
 
end

Here’s an example controller. This particular controller is an excerpt from the demo application provided to demonstrate the ActionFlow framework.

class SimpleFormController < FlowApplicationController
 
  def initialize
  
    # Start the flow with the initialization view
    start_with :init
    
    # End the flow on the qui view
    end_with :quit
    
    # Redirect the invalid flows to the index of
    # the current controller so the flow initializes
    # correctly
    redirect_invalid_flows :action => :index
    
    
    # Rescue potential errors
    upon :StandardError => :quit_with_error
    
    
    
    # Map the init step
    view_step :init do
    
      # Map some events to steps
      on :next => :hello_world  
      on :raise_error => :raise_error
      on :quit => :quit
      
      # Handle potential errors
      upon :StandardError => :quit_with_error
      
    end
    
    
    # Map the hello world step
    view_step :hello_world do
    
      # Map some events to steps
      on :hello_you_too => :quit
      on :back => :init
    
      # Handle potential errors
      upon :StandardError => :quit_with_error
      
    end
    
    
    # Map the error raising step
    action_step :raise_error do
      # Nothing to map, we'll throw an error
      # but the controller will rescue it.
    end
    
    
    # Map the hello world step
    action_step :quit_with_error do
      
      # Use this method as a step implementation
      method :show_error_and_quit
      
      # Map an event
      on :quit => :quit
      
    end
    
    
    # Map the quit step
    view_step :quit
    
  end
  
  
  
  def raise_error
  
    raise(StandardError.new, "Just a test")
  
  end
  
  
  def show_error_and_quit
    flash[:error] = "If you see this message, there was an error and your session has been terminated."
    event :quit
  end
  
 
end

~~DISCUSSION~~

 
creating_controllers.txt · Last modified: 2007/06/06 16:16 by lucboudreau
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.