Jquery Tokeninput& Acts-as-taggable 不适用于父子子嵌套表单
我的表单是这样构建的:
<%= 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 %>
现在,当我转到该页面时,使用以下行时出现错误: "data-pre" =>; @product.tags.map(&:attributes).to_json
这是 nil:NilClass 的未定义方法标签,但是当我把它拿走时一切都很好。这是某种类型的 TokenInput 错误吗?还有其他人需要处理这个问题吗?
产品控制器:
def new
@location = Location.new
product_date = @location.product_dates.build
product_date.products.build
end
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只是没有设置您的
@product
变量 =>它是nil
。您应该显示您的控制器
编辑:
替换:
为:
这也适用于
edit
。这真的很有意义:你不能调用你没有设置的东西。
You simply didn't set your
@product
variable => it'snil
.You should show your controller
EDIT:
replace:
with:
This should work for
edit
as well.It's really good sense here: you can't invoke something you didn't set.