4
I have three models in my application, Order
, Product
and Items
. Within Items
I have the following code:
class Item < ActiveRecord::Base
belongs_to :product
belongs_to :order
end
I have a form where I add a new one Order
, then I am redirected to the 'show.html.erb' view, where I have an ajax form to add the items, with fields to insert the products related to these items, as follows:
<%= form_for [@order, @order.items.build], remote: true do |f| %>
And a listing of these items/products. It is in this listing that I am having problems: I want my list to have the following code:
<% @order.items.each do |i| %>
<tr>
<td><%= i.product.name %> </td>
</tr>
<% end %>
But a rendering error is released, saying that the method name
does not exist for null object and, it is necessary that I update the page to work. But, if I change this line to that \:
<td><%= i.product_id %> </td>
Rendering is done correctly.
In view of this error, I believe the problem is directly linked to the json return of my object @item
. But I have no idea how to solve, someone can help me?
Error only gives when you add a new item per ajax? If you update the page works?
– GuiGS