Rails plugin: acts_as_wizard
Posted by Paolo Wed, 03 May 2006 04:29:00 GMT
SeeSaw has just released his new rails plugin: acts_as_wizard.
This plugin will let you build wizards on top of existing controllers, giving you the ability to chain pages and actions to provide wizard-like behavior through pages.
Our goal is to give our apps better usability.
This plugin is pretty simple and will switch your pages to a special layout if invoked with a wizard=true parameter.
Wizard’s steps are defined in classes like this one:
class CreateCatAndDogWizard < Wizard::Base
add_step :name => 'Insert your cat',
:controller => 'cats',
:actions => [:new, :create]
add_step :name => 'Insert your dog;',
:controller => 'dogs',
:actions => [:new , :create]
add_step :name => 'Finished!',
:controller => 'main',
:actions => [:finished ]
endTo get a glimpse, take a look at acts_as_wizard in two minutes or the longer acts_as_wizard step by step.
Note it’s in his early stages, so feedback is really appreciated. You can also give us feedback commenting on this post.




Well done! I’l give it a try ASAP and let you know my comments! :)
Hello Again. Using your acts_as_wizard has been a pleasure!
One question, in the series of actions I am trying to turn into a wizard, I have my second action which DEPENDS on the first. The url I need to redirect to must include some additional parrameters, like this:
However, I get an error like this: undefined local variable or method `params’ for FooController:Class
What should I do?
Also, I’ve noticed that the on_wizard_rewrite doesn’t seem to work with my named routes … so if I do some_controller_url(:action => ‘actionname’) the rewrite failes, but if I do :controller => ‘some_controller’ :action => ‘actionname’ then everything works…
You can add addictional parameters directly to your link_to or render call, not the on_wizard_rewrite class method.
I would do something like:
When this link will be rewritten, it should substitute with keeping your additional params.You can even consider to add additional params only when invoked as a wizard with something like:
opts = {:action => 'show'} opts[:waiting_list_id] = params[:waiting_list_id] if params[:wizard] link_to "Show", optsThis will help you keep your urls clean if you need to pass extra params only in wizard mode.
For the named route thing, I’ll dig on it and give you an answer asap.
I installed the plugin and have used it with great success. However, I’ve run into a situation where I’d like to include the same action in multiple wizards….
Basically, I’d like to do the following within the controller..
class PeopleController < ApplicationController acts_as_wizard :create_new_member on_wizard_rewrite(:create_new_member,
Do you think it would be easy to modify your plugin to do this?
Hi Dan, right now acts_as_wizard keeps a reference to the Wizard object inside your controller, and that’s sadly just one. So it’s not able to ‘understand’ multiple wizards at once.
It could be done for sure, but It means to have different parameter values triggering different wizards, eg: izard=>true would become izard=>‘create_new_employee’ and izard=>‘create_new_member’.
acts_as_wizard will undergo a big refactoring as I wanna get rid of unecessary code inside the controllers. Everything should be configured in the Wizard Class only.
We’ll consider introducing what you asked just after this refactoring. Maybe you wanna take a look at the source code and help us doing it :-)
Thanks for the hint!
Ah, cool, I was hoping a refactoring of that sort was coming… I’m definitely willing to extend it and add the multi-wizard support… Any idea on the timeline around the refactoring?
We’re going to do it in a week or so, but we’re attending the Italian Java Conference this week so I wouldn’t take this date for granted. I can tell you we need this feature too, so It will be developed for sure.
Hey Dan, check out the new acts_as_wizard version and let me know if works for you!
the following monkey patch:
class Symbol def to_str id2name end end
is deeply evil, as it breaks Struct in a very non-obvious way.
Many many things rely on Struct, including the rails suite of unit tests. Ahem.
Bad, bad monkey.