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
You simply didn’t set your
@productvariable => it’snil.You should show your controller
EDIT:
replace:
with:
This should work for
editas well.It’s really good sense here: you can’t invoke something you didn’t set.