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 ] 
end

To 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.

Posted in ,  | Tags , , ,  | 10 comments | no trackbacks

Trackbacks

Use the following link to trackback from your own site:
http://blog.seesaw.it/articles/trackback/70

Comments

  1. Avatar federico said about 15 hours later:

    Well done! I’l give it a try ASAP and let you know my comments! :)

  2. Avatar Peter Brown said 16 days later:

    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:

    on_wizard_rewrite(
        {:action => 'show'}, 
        {:controller => 'fulfillment_block', :action => 'list', :waiting_list_id => params[:waiting_list_id]})

    However, I get an error like this: undefined local variable or method `params’ for FooController:Class

    What should I do?

  3. Avatar Peter Brown said 16 days later:

    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…

  4. Avatar Paolo said 16 days later:

    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:

    link_to "Show", :action => 'show', :waiting_list_id => params[:waiting_list_id]
    
    When this link will be rewritten, it should substitute
    :action => 'show'
    with
    :controller => 'fulfillment_block', :action => 'list'
    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", opts 
    

    This 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.

  5. Avatar Dan Hatfield said 50 days later:

    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,

    {:action=>'list'}, 
      {:controller => 'members',:action => 'new'})
    acts_as_wizard :create_new_employee
    on_wizard_rewrite(:create_new_employee,
    {:action=>'list'}, 
    {:controller => 'employees',:action => 'new'})

    Do you think it would be easy to modify your plugin to do this?

  6. Avatar Paolo said 50 days later:

    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!

  7. Avatar Dan Hatfield said 54 days later:

    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?

  8. Avatar Paolo said 54 days later:

    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.

  9. Avatar Paolo said 76 days later:

    Hey Dan, check out the new acts_as_wizard version and let me know if works for you!

  10. Avatar Michael Johnston said 337 days later:

    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.

Comments are disabled


SeeSaw srl - Via Monte Pasubio, 8 37126 Verona - tel +39 045 4857457 fax 045 4851151 P.Iva 03609790237