Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Django-like forms
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
spec
.gitignore
CHANGELOG
Gemfile
Gemfile.lock
LICENSE
README.textile
TODO.txt
deps.rip
formidable.gemspec
formidable.pre.gemspec
tasks.rb

README.textile

About

Formidable takes care about your forms. You write a class and

  • Get logic out of your views.
  • Get logic out of your controllers (presenter pattern).
  • Validations will work even if the form can’t be mapped directly to the models.
  • You can unit test your forms directly without touching the template layer at all.
  • Validations
  • Coercions

Forms contains quite complex logic which definitely shouldn’t be in your views

Defining Forms

Saving Forms

Validations

Renderers

Custom Fields

Ideas

JS validation plugin

Usage

Form Definitions


Controller Code

class Posts
  def new
    @form ||= PostForm.new
    @form.attributes[:method] = "POST"
  end
  
  def edit
    @form ||= PostForm.new
    @form.attributes[:method] = "PUT"
  end
  
  def create(raw_data)
    @form = PostForm.new(nil, raw_data)
    if @form.save
      redirect url(:posts)
    else
      self.new
    end
  end
  
  def update(id, raw_data)
    @form = PostForm.new(nil, raw_data)
    if @form.update(id)
      redirect url(:posts)
    else
      self.edit
    end
  end
end

You can find more examples at the examples directory.

Links

Something went wrong with that request. Please try again.