Actsaswizard is a project mainly written in Ruby, based on the MIT license.
A Rails plugin to make creating a wizard easy and with a lot less code
Build dynamic wizards on the web with very little code. Sticking to convention over configuration, I think that this plugin will be useful and familiar to seasoned Rails developers, but easy enough for the new Rails developers, too.
I hope the example makes the code self explanatory.
I would also love for someone to come along and help me write tests for this. Not using TDD goes totally against my normal coding style. This started as a spike, and morphed its way into code I didn't want to throw away. Now I've gotten so excited over it that I just want to get it out there for feedback.
class Employee < ActiveRecord::Base acts_as_wizard :personal_information, :work_information end
class PersonalInformation < ActiveRecord::Base acts_as_wizard_page :employee end
class EmployeesController < ApplicationController def new @employee = Employee.new @employee.save redirect_to edit_employee_url(@employee) end
def edit
@employee = Employee.find(params[:id])
@page = @employee.get_wizard_page
end
def update
@employee = Employee.find(params[:id])
@page = @employee.get_wizard_page
if @page.update_attributes(params[@employee.get_current_wizard_step])
@employee.switch_wizard_page(params[:direction])
@employee.save
redirect_to :action => :edit
else
render :action => :edit
end
end
end
<%=javascript_include_tag :defaults %> <% form_for(@employee) do |f| -%> <%= error_messages_for :page %>
<hr/>
<table class="controls">
<tr>
<td>
<%= previous_wizard_button @employee %>
</td>
<td>
<%= next_wizard_button %>
</td>
</tr>
</table>
<% end -%>
<%= wizard_page_text_field :name %>
class CreateEmployees < ActiveRecord::Migration def self.up create_table :employees do |t| t.integer :state
t.timestamps
end
end
def self.down drop_table :employees end end
class CreatePersonalInformations < ActiveRecord::Migration def self.up create_table :personal_informations do |t| t.integer :employee_id t.string :name
t.timestamps
end
end
def self.down drop_table :personal_informations end end
Adam Klunick at Quantiverge, Inc. for having faith that there had to be better way to make a wizard, and for trying Rails even when he had never written Ruby.
Mike Hagedorn for writing a wizard how-to for Pragmatic Studios - Advanced Rails Recipes. The recipe put me on this path.
Copyright (c) 2008 Amos L. King, released under the MIT license