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:
$ bundleOr install it yourself as:
$ gem install incredibleUsage
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: :bazEach 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:migrateNote how all the columns refer to a question in your YAML file.
Then create a controller:
rails g controller forms/buildAdd Routes into config/routes.rb:
resources :forms do
resources :build, controller: 'forms/build'
endNext 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
endNext, you'll need to have a controller that creates your model and redirects to the form. Run this:
rails g controller formsThen edit your controller:
class FormsController < ApplicationController
def create
form = Form.create
redirect_to new_form_build_path(form_id: form.id)
end
endMore docs coming soon!
Contributing
See CONTRIBUTING.md
License
The gem is available as open source under the terms of the MIT License.