【发布时间】:2011-10-02 09:42:30
【问题描述】:
是否有 Mongoid 2.0 的表单生成器? 它会自动从模型生成表单。
谢谢
【问题讨论】:
标签: ruby-on-rails mongoid formbuilder
是否有 Mongoid 2.0 的表单生成器? 它会自动从模型生成表单。
谢谢
【问题讨论】:
标签: ruby-on-rails mongoid formbuilder
为什么不直接使用 Rails sacffolding?
【讨论】:
https://github.com/mcasimir/document_form
gem 文档格式
这是我从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 %>
如果您决定试一试,我将不胜感激任何形式的反馈。
【讨论】: