【发布时间】:2019-03-17 06:10:05
【问题描述】:
根据https://guides.rubyonrails.org/layouts_and_rendering.html#using-partials上的信息框:
Rails 还在一个名为的部分中提供了一个计数器变量 按集合,以部分的标题命名,后跟 _柜台。例如,在渲染集合@products 时,部分 _product.html.erb 可以访问变量 product_counter 它索引它在 封闭视图。
但是,在我的部分中引用计数器时出现错误。这是父视图:
<%= render partial: 'comments/comment_template', collection: @post.comments, as: :c %>
这里是_comment_template.html.erb的相关部分:
<%= comment_template_counter %>
这是错误:
undefined local variable or method `comment_template_counter' for #<#<Class: [etc.]
我错过了什么?
【问题讨论】:
-
我已将部分内容从“_comment_template.html.erb”重命名为“_comment.html.erb”(并更新了各种参考资料),但错误仍然存在。
标签: ruby-on-rails