2

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

ファクトラ/新しいビューでジェムを使用して、アイテムファクチュラを追加しました。

<%= 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#new の NoMethodError

/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) を使用しています


(ローカル IP アドレス)を追加する%Aと、接続がローカル システムの IPv4 アドレスまたは IPv6 アドレスのどちらを介して到着したかを示す必要があります。

4

1 に答える 1

5

わかりました私はそれを解決しました。ファクトラ/新しい形式で、私は置く必要があります

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

これが、別のヘルパーであるため、link_to_add と link_to_remove が見つからない理由でした。

于 2013-02-17T00:02:53.927 に答える