我对 Rails 很陌生,所以请原谅任何非常不准确的术语。首先,一些背景:我正在为一个小型分析实验室构建一个示例跟踪网络应用程序。能够将批量提交表单分成三列会特别巧妙。一个批次与第 1 列中的多个测试相关联,批次信息输入第 2 列,单个 sample 在第 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"
在此先感谢您的帮助!
最佳答案
事实证明,当我发布这个问题时,我陷入了一些疯狂的阴霾,并没有想到要在 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
这给了我一个很好地拆分的大嵌套表单。
关于ruby-on-rails - 将表单(tastic)拆分为三列布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4720688/