Giter Club home page Giter Club logo

multi_stage_form's Introduction

MultiStageForm

Plugin for creating multi stage form

This is only prototype.

TODO

* improve documentation
* make tests
* minimize code in controller

Usage

Model

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

Controller

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

View

new.html.haml

= error_messages_for( :post )
= render( :partial => "step_#{@post.current_stage}" )

_step_1.html.haml

- 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' )

_step_2.html.haml

- 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

multi_stage_form's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.