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