Ruby on rails 3 Rails 3 Nester_Form Gem:如何自定义模板?

Ruby on rails 3 Rails 3 Nester_Form Gem:如何自定义模板?,ruby-on-rails-3,rubygems,nested-forms,Ruby On Rails 3,Rubygems,Nested Forms,我正在使用rails 3 gem,希望更改插入的默认蓝图的生成方式。我不知道这段代码是从哪里来的,以及如何添加代码来修改它 我目前正在为我的表单使用分部代码: /app/views/units/_unit.html.haml %tr %td=f.text_field :units %td=f.text_field :dispatched %td=f.text_field :onscene %td=f.text_area :actions ... %table.uni

我正在使用rails 3 gem,希望更改插入的默认蓝图的生成方式。我不知道这段代码是从哪里来的,以及如何添加代码来修改它

我目前正在为我的表单使用分部代码:

/app/views/units/_unit.html.haml

%tr
  %td=f.text_field :units 
  %td=f.text_field :dispatched
  %td=f.text_field :onscene
  %td=f.text_area  :actions
...    
%table.units
  %th Unit
  %th Dispatched%th On Scene
  %th Actions
=f.fields_for :units

%p= f.link_to_add "Add a unit", :units
...
调用分部函数的代码段:

/app/vies/reports/_form.html.haml

%tr
  %td=f.text_field :units 
  %td=f.text_field :dispatched
  %td=f.text_field :onscene
  %td=f.text_area  :actions
...    
%table.units
  %th Unit
  %th Dispatched%th On Scene
  %th Actions
=f.fields_for :units

%p= f.link_to_add "Add a unit", :units
...
我有所有的核心功能,除了模板。它是由gem在运行时自动创建的。此模板导致模板使用非常简单的HTML标记

与以下内容类似:

<div id="units_fields_blueprint" style="display:none">
  <p class="fields">
    <input id="report_units_attributes_new_units_unit" name="report[units_attributes][new_units][unit]" size="30" type="text">
    <input id="report_units_attributes_new_units_dispatched_1i" name="report[units_attributes][new_units][dispatched(1i)]" type="hidden" value="2011">
    ...
  </p>
</div>
我希望蓝图有部分的表格格式,我只是不知道如何到达那里


如果您有任何帮助,我们将不胜感激。

仅包含一个表行的部分(如上面列出的)在放入blueprint div中时将不是有效的标记

以下代码不是有效的标记

<div>
  <tr>
    <td>Content</td>
  </tr>
</div>
例如,某些浏览器chrome会试图纠正这种错误的标记,这是通过去除tr和td标记来完成的

要使这种类型的代码与嵌套的表单一起工作将非常复杂,需要在javascript字符串中创建蓝图,并且需要对生成器进行修改,以停止在代码块中自动围绕插入的代码

这些更改在其中引用了github用户elmatou创建的分支


获得类似外观的另一个选项是使用div和span,并使用CSS创建网格结构。这是一个CSS密集型的过程,但允许使用嵌套表单而无需修改。

嵌套表单gem不创建任何模板,它只提供帮助程序来插入部分内容,并提供javascript来动态添加和删除部分内容。除非Ryan最近改变了。我一定有点不清楚,我道歉。我希望能够定制的是蓝图,而不是创建带有嵌套for的页面时生成的模板。这可以在原始文章的最后一个代码块中看到。我想这里还有其他的东西在起作用,因为我只是使用嵌套表单gem对我的一些应用程序进行了双重检查。他们都没有插入任何蓝图,只是按照我的布局呈现了部分,这与我认为你期望的类似。你确定吗?当您从使用嵌套for呈现的页面查看源代码时,是否没有插入?如果没有,你是如何要求部分被呈现的?我发现,一篇文章讨论了插件是如何工作的,它讨论了蓝图。我提取了一个小引号:嵌套表单基本上为嵌套表单字段创建了一个蓝图,并将其放置在表单后面的一个隐藏分区中。单击link_to_add创建的链接将通过jQuery在其同类的最后一个嵌套表单之后插入另一个嵌套表单。