【问题标题】:In Rails, how do I customise the link_to_add layout when using simple_nested_form在 Rails 中,使用 simple_nested_form 时如何自定义 link_to_add 布局
【发布时间】:2012-09-04 05:04:24
【问题描述】:

我正在尝试确定在 Rails 3 中使用 nested_form/simple_form gem 时是否可以自定义由 link_to_add 插入的 HTML。

目前它生成一个 div,但我希望它生成一个表格行。

我看过一个使用 Cocoon gem 的示例,但我更喜欢使用 nested_form。

当前的代码非常简单:

table.table.table-striped
  tr 
    th Name
    th Notes
    th $ Value
    th
    = f.simple_fields_for :client_contracted_rates do |ccr|
      tr
        td = ccr.text_field :name, :class => "span2"
        td = ccr.text_field :notes, :class => "span2"
        td = ccr.text_field :value, :class => "span1"
        td = ccr.link_to_remove "x", :class => "btn btn-mini btn-danger"

= f.link_to_add "+ Add Contracted Rate", :client_contracted_rates, :class => "btn pull-right"

我希望生成一个表格行,或者至少与 div 和输入默认值不同。

干杯,

乔诺

【问题讨论】:

    标签: ruby-on-rails ruby nested-forms simple-form


    【解决方案1】:

    我最终没有使用 f.link_to_add,而是使用了 = link_to 方法。

    这使我可以根据需要将 = link_to 包装在表格行内。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      • 2012-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多