Project

incredible

0.0
No commit activity in last 3 years
No release in over 3 years
Build multi-page forms like a General
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

Runtime

~> 5.1.4
~> 1.3.2
 Project Readme

Build Status Coverage Status Code Climate Gem Version License

Incredible

Build multi-page forms like a General.

Incredible uses the power of Wicked to allow you to build multi-page, ActiveRecord model-based, Rails forms using a simple YAML-based format.

Installation

Add this line to your Rails application's Gemfile:

gem 'incredible'

And then execute:

$ bundle

Or install it yourself as:

$ gem install incredible

Usage

NOTE: Incredible is still a work in progress and at an early stage, so these docs are subject to change (and definitely need improving!)

First, create a YAML file in config/forms - for example config/forms/my_awesome_form.yml.

Here's an example:

form:
  name: 'Test form'
  steps:
    step1:
      template: foo
      rules:
        name:
          'Mike': :step3
      questions:
        - name: :name
          title: Your full name
          widget: :input
        - name: :postcode
          title: Your postcode
          widget: :input
    step2:
      template: bar
      questions:
        - name: :email
          title: Email
          widget: :email
        - name: :phone_number
          title: Phone Number
          widget: :tel
    step3:
      template: :baz

Each step must have a template, and questions as a minimum.

Next create a model:

rails g model form name:string postcode:string email:string postcode:string
rails db:migrate

Note how all the columns refer to a question in your YAML file.

Then create a controller:

rails g controller forms/build

Add Routes into config/routes.rb:

resources :forms do
  resources :build, controller: 'forms/build'
end

Next include Incredible::Wizard in your controller

class Forms::BuildController < ApplicationController
  include Incredible::Wizard

  form 'my_awesome_form'
end

(Where my_awesome_form is the name of the YAML file you created)

Next add show, create and new methods to your controller

class Forms::BuildController < ApplicationController
  include Incredible::Wizard
  
  form 'my_awesome_form'
  
  def show
    render_wizard nil, template: "forms/#{template}"
  end

  def update
    @form = Form.find(params[:id])
    render_wizard @form
  end
  
  def new
    redirect_to wizard_path(steps.first, foster_check_id: foster_check.id)
  end
  
end

Next, you'll need to have a controller that creates your model and redirects to the form. Run this:

rails g controller forms

Then edit your controller:

class FormsController < ApplicationController
  
  def create
    form = Form.create
    redirect_to new_form_build_path(form_id: form.id)
  end
  
end

More docs coming soon!

Contributing

See CONTRIBUTING.md

License

The gem is available as open source under the terms of the MIT License.