【问题标题】:ryanb / nested_form undefined method `link_to_remove' for #<ActionView::Helpers::FormBuilderryanb / nested_form 未定义方法 `link_to_remove' 用于 #<ActionView::Helpers::FormBuilder
【发布时间】:2013-02-16 23:10:58
【问题描述】:

我对 gem nested_form 有一点问题。我有:

class Factura < ActiveRecord::Base
 attr_accessible :itemfacturas_attributes
 has_many :itemfacturas
 has_many :productos, :through => :itemfacturas
 accepts_nested_attributes_for :itemfacturas, :reject_if => lambda { |a| a[:descripcion].blank? }, :allow_destroy => true

还有 ItemFactura 类

class Itemfactura < ActiveRecord::Base
 attr_accessor :vu, :vt, :descripcion
 belongs_to :factura
 belongs_to :producto

我使用 facturas/new 视图中的 gem 来添加 itemfacturas。

<%= f.fields_for :itemfacturas do |b| %>
        <%= render 'itemfacturas/itemfacturas', f: b %>
 <% end -%>
 <%= f.link_to_add "Agregar item", :itemfacturas %>

而部分是:

<%= f.number_field :cantidad, :min => 0, :value => 1 %>
<%= f.text_field :descripcion, :class => "desc_autocomplete" %>
<%= f.text_field :vu %>
<%= f.text_field :vt %>
<%= f.hidden_field :producto_id%>
<%= f.link_to_remove "Eliminar" %>

但我有这个错误:

Facturas 中的 NoMethodError#new

显示 /Users/fabricioflores/desarrollo/facturacion/app/views/itemfacturas/_itemfacturas.html.erb 提出第 7 行的位置:

未定义的方法 `link_to_remove' 用于

如果我评论包含 link_to_remove 的行,我有另一个关于 link_to_add 的错误

我按照https://github.com/ryanb/nested_form 的步骤进行操作,但没有成功。我正在使用 Rails 3.2.9 和 nested_form (0.3.1)

【问题讨论】:

    标签: ruby-on-rails ruby gem nested-forms nested-attributes


    【解决方案1】:

    好的,我解决了。我需要以 facturas/new 的形式输入

    <%= nested_form_for @factura do |f| %>
    

    这就是找不到link_to_add和link_to_remove的原因,因为是不同的helper。

    【讨论】:

      猜你喜欢
      • 2020-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 2011-01-14
      • 2011-11-08
      • 2012-05-21
      相关资源
      最近更新 更多