Form Builder for Mongoid: DocumentForm

DocumentForm is a Rails3 FormBuilder DSL that aims to provide a super fast and simple form-building tool to edit Mongoid documents in Rails3. DocumentForm is a fork of formtastic.

Basic Usage

DocumentForm allows you to create a form almost without coding.


class Person
  include Mongoid::Document
  include Mongoid::MultiParameterAttributes

  validates_presence_of :name

  field :name
  field :secret,            :private => true
  field :birthday,          :type => Date
  field :department_number, :type => Integer, :range => 1..10

  field :description,       :long => true


  <% document_form_for @object do |f| %>
    <%= f.inputs %>
    <%= f.buttons %>
  <% end %>
  • Fields are rendered in the declaration order.
  • Fields that has :private => true option are not rendered.

File upload support

DocumentForm will render automatically file inputs for:

  • Carrierwave
  • Paperclip
  • Any other upload library that generates a _filename field in your model

DocumentForm will configure automatically your form with :multipart => true for each models that has at least a _filename field.


Put this in your Gemfile

  gem document_form

and run:

  bundle install

Some advanced examples

Belongs_to association

class Person
  include Mongoid::Document

  referenced_in :department

Will render a drop down list of departments

Has many association

class Person
  include Mongoid::Document

  references_many :departments, :stored_as => :array

Will render a sequence of checkboxes to pick multiple departments

Other usage details

Please refer to formtastic documentation for a more detailed usage guide until DocumentForm documentation will be available.