2011-10-02 66 views

回答

0

爲什麼不直接使用Rails sacffolding?

+0

由於腳手架是爲入門而設計的,並非用於構建[naked-objects](http://en.wikipedia.org/wiki/Naked_objects)應用程序。 – yfeldblum

+0

不,這是因爲當您在模型上添加新字段時,它不會自動將字段添加到_form.html.erb。 使用MONGOID,您無需爲模型上添加的每個字段再運行一次新的遷移。這有點神奇:) http://web2py.com/的一些事情。 – Unitech

0

https://github.com/mcasimir/document_form

寶石document_form

這是一個從https://github.com/justinfrench/formtastic叉子我所做的,只是搬到Mongoid 2.

型號

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 

查看

<% document_form_for @object do |f| %> 
     <%= f.inputs %> 
     <%= f.buttons %> 
    <% end %> 

這是一個基本的例子:這裏的表單生成器將呈現以相同的順序中的字段聲明它們,跳過那些誰:private => true

如果你不着急,你想要的東西更靈活,你可以始終使用相同的語法formtastic指定領域的廣告選項,這樣的事情:

<% 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 %> 

如果你決定給它試一試,我會欣賞任何形式的反饋。