0

部分文件:_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 个小时在上面,找不到任何提示。谁能给点提示?

4

0 回答 0