部分文件:_link_topic_type.html.erb:
// debug info to check the passed in variables
<p>current_topic_type: <%= current_topic_type %></p>
<p>topic_type: <%= topic_type %></p>
<p>active: <%= current_topic_type == topic_type %></p>
<% if current_topic_type == topic_type %>
<li class="active">
<% else %>
<li>
<% end %>
<%= link_to user.student? ? Topic::TOPIC_TYPES[topic_type] : '我的公告',
topics_path(user_id: user, course_id: course, topic_type: topic_type),
class: 'topic-type-action' %>
</li>
在操作视图模板中调用此文件4次:
<% (1..4).each do |tt| %>
<%= render partial: 'link_topic_type',
locals: { user: user, course: course, current_topic_type: topic_type, topic_type: tt } %>
<% end %>
从输出中,'current_topic_type'和'topic_type'值都是正确的,但'active'值始终为false:
current_topic_type: 1
topic_type: 1
active: false
current_topic_type: 1
topic_type: 2
active: false
current_topic_type: 1
topic_type: 3
active: false
current_topic_type: 1
topic_type: 4
active: false
这很奇怪。我花了2个小时就找不到任何暗示。任何人都可以给出一些暗示吗?