Plugin for creating multi stage form
This is only prototype.
* improve documentation * make tests * minimize code in controller
class Post < ActiveRecord::Base validates_presence_of(:name_1, :name_2) attr_accessor( :current_stage ) multi_stage_form( :validates_on_stage => { 1 => [:name_1], 2 => [:name_2] }, :stages => 2 ) end
class PostsController < ApplicationController def index end def new @post = msf_new(params[:current_stage]) end def create @post = msf_create(params[:post]) multi_stage_form(@post) end protected def stage_2 #do something on stage 2 end end
= error_messages_for( :post ) = render( :partial => "step_#{@post.current_stage}" )
- form_for( @post ) do |f| = f.hidden_field( :current_stage, :value => @step_id ) %ul %li = f.label( :name_1 ) = f.text_field( :name_1 ) %li = f.submit( 'next' )
- form_for( @post ) do |f| = f.hidden_field( :current_stage, :value => @step_id ) %ul %li = f.label( :name_2 ) = f.text_field( :name_2 ) %li = f.submit( 'create' )
Copyright © 2009 Artur Małecki