Reputation: 27212
I have form which is built like this:
<%= form_for @location do |f| %>
<%= f.fields_for :product_dates do |d| %>
<%= d.fields_for :products |p| %>
<%= p.text_field :tag_list,"data-pre" => @product.tags.map(&:attributes).to_json %>
Now when i go to the page i get an error when using the line: "data-pre" => @product.tags.map(&:attributes).to_json
which is undefined method tags for nil:NilClass
but everything is fine when i take it away. This some type of TokenInput bug? Anyone else had to deal with this?
ProductsController:
def new
@location = Location.new
product_date = @location.product_dates.build
product_date.products.build
end
Upvotes: 0
Views: 416
Reputation: 115531
You simply didn't set your @product
variable => it's nil
.
You should show your controller
EDIT:
replace:
<%= p.text_field :tag_list,"data-pre" => @product.tags.map(&:attributes).to_json %>
with:
<%= p.text_field :tag_list,"data-pre" => p.object.tags.map(&:attributes).to_json %>
This should work for edit
as well.
It's really good sense here: you can't invoke something you didn't set.
Upvotes: 2