Automatic Formbuilder for Mongoid 2.0 ? Rails
Is there a formbuilder for Mongoid 2.0 ? Wh开发者_开发问答ich generates automatically a form from a model.
Thanks
Why not just use Rails sacffolding?
https://github.com/mcasimir/document_form
gem document_form
It's a fork from https://github.com/justinfrench/formtastic i've made, just moved to Mongoid 2.
Model
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
end
View
<% document_form_for @object do |f| %>
<%= f.inputs %>
<%= f.buttons %>
<% end %>
This is a basic example: here the form builder will render the fields in the same order they are declared, skipping those who have :private => true
.
If you are not in a hurry and you want something more flexible you can always specify fields ad options using the same syntax as formtastic, something like this:
<% f.inputs do %>
<%= f.input :title %>
<%= f.input :published, :label => "This post is published" %>
<%= f.input :section_id %>
<%= f.input :image_filename, :hint => "540x300" %>
<% end %>
If you'll decide to give it a try it i will appreciate any sort of feedback.
精彩评论