5

我对 Rails 很陌生,所以请原谅任何非常不准确的术语。首先,一些背景:我正在为一个小型分析实验室构建一个示例跟踪 Web 应用程序。能够将批量提交表单分成三列会特别巧妙。一个批次与第 1 列中的多个测试相关联,批次信息输入到第 2 列,单个样品在第 3 列中命名。理想情况下,第 3 列底部有一个漂亮的大提交按钮,可以推动整个混乱通过。

我使用 960(12 列)来生成 CSS,使用 formtastic 来生成表单。我的第一个倾向是通过三个 div 设置列并将表单离散地拆分为每个 div,但是,我不确定如何将表单拆分为 div,同时保持我称之为数据的持久性跨所有列。我什至应该使用 div 吗?这是一些代码显示我的一般要点:


.grid_4
  # Test associating stuff

.grid_4
  = semantic_form_for @batch do |f|
    = f.inputs :name => "Batch Info" do 
      = f.input :sampling_date, :required => false 
      = f.input :experiment_name, :required => false 
      = f.input :notes, :as => :text 

.grid_4
  # The page obviously breaks without this line, but it makes the form only
  # pertain to the inputs in this column.
  = semantic_form_for @batch do |f|
    # The sample and test association stuff will be nested forms
    = f.semantic_fields_for :samples do |sample_form|
      = sample_form.input :sample_name
    = f.buttons do 
      = f.commit_button :label => "Submit batch"

提前感谢您的帮助!

4

2 回答 2

2

事实证明,当我发布这个问题时,我陷入了疯狂的迷雾之中,并没有想到要在 formtastic 助手内部进行网格化。例如:


= semantic_form_for @something do |f|
  .grid_4
    # Part 1 of form
  .grid_4
    # Part 2 of form
  .grid_4
    # Part 3 of form

这给了我一个很好分割的大嵌套形式。

于 2011-01-18T22:10:03.240 回答
0

萨米是你的答案。我在我的一个项目中使用过它,我必须说它很简单而且很有效。

于 2011-01-18T05:33:19.843 回答