助手/子类别_helper.rb:
module SubcategoriesHelper
def has_topic_headings?
self.topic_headings
end
end
类别/show.html.erb 包含
<% @category.subcategories.each do |subcategory| %>
<li>
<h6>
<%if subcategory.has_topic_headings? %>
<%= link_to subcategory.name, subcategory, data: :has_topic_headings %>
<% else %>
<%= link_to subcategory.name, subcategory %>
<% end %>
</h6>
<hr>
</li>
<% end %>
页面返回
undefined method `has_topic_headings?' for #<Subcategory:0xa68748c>
请注意,视图页面属于类别,而不是子类别。