I have a little problem with gem nested_form. I have:
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
and the ItemFactura class
class Itemfactura < ActiveRecord::Base
attr_accessor :vu, :vt, :descripcion
belongs_to :factura
belongs_to :producto
I used the gem in the facturas/new view to add itemfacturas.
<%= f.fields_for :itemfacturas do |b| %>
<%= render 'itemfacturas/itemfacturas', f: b %>
<% end -%>
<%= f.link_to_add "Agregar item", :itemfacturas %>
And the partial is:
<%= 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" %>
But I have this error:
NoMethodError in Facturas#new
Showing
/Users/fabricioflores/desarrollo/facturacion/app/views/itemfacturas/_itemfacturas.html.erb
where line #7 raised:undefined method `link_to_remove’ for
If I comment line that contains link_to_remove I have another error about link_to_add
I followed steps from https://github.com/ryanb/nested_form but it did’t work. I’m using Rails 3.2.9 and nested_form (0.3.1)
Ok I solved it. In the form of facturas/new I need to put
This was the reason that can’t find the link_to_add and link_to_remove, because is a different helper.