public
Description: Action Sequencer for Ruby on Rails
Homepage: http://monkey-patch.me/ruby_on_rails/action_sequence
Clone URL: git://github.com/boof/action_sequence.git
name age message
file .gitignore Sun Jul 13 04:41:10 -0700 2008 Made walker more convenient. * walker param de... [boof]
file MIT-LICENSE Sun Jul 13 04:06:53 -0700 2008 Initial import. [boof]
file README.rdoc Mon Jul 14 00:45:57 -0700 2008 Added docs. [boof]
file Rakefile Mon Jul 14 00:45:57 -0700 2008 Added docs. [boof]
file init.rb Sun Jul 13 04:06:53 -0700 2008 Initial import. [boof]
directory lib/ Mon Jul 14 00:45:57 -0700 2008 Added docs. [boof]
directory tasks/ Sun Jul 13 04:06:53 -0700 2008 Initial import. [boof]
directory test/ Mon Jul 14 00:45:57 -0700 2008 Added docs. [boof]
README.rdoc

ActionSequence

Multipage form routing for controller actions.

This plugin adds simple sequencing functionality to controller actions. ActionSequence does so by tracking a so called walker parameter.

Features

  • seperates form routing from controller actions
  • easy DSL (ActionSequence::Initializer)
  • easy to customize because of it’s simple layout (ActionSequence / ActionSequence::Walker / ActionSequence::Step)
  • tested (with test/spec)

Example

  class ItemController < ApplicationController

    # Initialize item sequence to fetch current index from params[:steps_name]
    sequence :item, :steps_name do
      enter_stuff do |s|
        if params[:back] then s.previous
        elsif @item.valid_stuff? then s.next
        end
      end
      select_other_stuff(:meth1, :meth2) do |s|
        if params[:back] then s.previous
        elsif @item.save then s[:finished]
        end
      end
    end

    before_filter :load_item
    before_filter :walk_item_sequence, :only => [:create, :update]

    # Executed when :select_other_stuff is walked.
    def meth1
      # does something
    end
    def meth2
      # does something
    end

    # Walks a specific step, means:
    #
    # Assigns step to @steps_name and runs required methods,
    # but doesn't execute steps decision block!
    def new
      walk_item_sequence :enter_stuff
    end
    def edit
      walk_item_sequence :enter_stuff
    end

    # Walk to params[:steps_name]
    def create
      unless item_sequence.finished_with? @steps_name
        render :action => :new
      else
        redirect_to :action => :list
      end
    end
    def update
      unless item_sequence.finished_with? @steps_name
        render :action => :edit
      else
        redirect_to :action => :list
      end
    end

  end

Copyright © 2008 Florian Aßmann, released under the MIT license