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.
DocumentForm allows you to create a form almost without coding.
class Person include ::Document include ::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 end
<% 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:
- Any other upload library that generates a
_filenamefield in your model
DocumentForm will configure automatically your form with
:multipart => true for each models that has at least a
Put this in your
Some advanced examples
class Person include ::Document referenced_in :department end
Will render a drop down list of departments
Has many association
class Person include ::Document references_many :departments, :stored_as => :array end
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.