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