我有一个简单的语句,如果两个变量中的至少一个为真,则执行该语句。我遇到的问题是,如果两个变量都为真,则语句会执行两次。我只需要它执行一次。
<% if intensity == "true" || @planned_intensity == "true" %>
<div class="red_dot"></div>
<% end %>
我在这里遗漏了一些明显的东西吗?在两个变量都为真的情况下,我得到两个红点。
//编辑
它似乎在其他地方,但我似乎找不到问题,这是整个块:
<% LogEntry.cal_entry(entry_date.to_date, @athlete.id).each do |entry| -%>
<% workouts = entry.workouts -%>
<% workouts.each do |workout| -%>
<% @planned_intensity = false %>
<% planned_workouts = workout.planned_workouts -%>
<% planned_workouts.each do |pworkout| -%>
<% @planned_times = pworkout.planned_workout_times -%>
<% @planned_times.each do |planned_time| -%>
<% if planned_time.zone > 1 %>
<% @planned_intensity = true %>
<% end %>
<% end %>
<% end %>
<% completed_workouts = workout.completed_workouts -%>
<% completed_workouts.each do |completed_workout| -%>
<li id="<%= workout.id.to_s() %>">
<% completed_workout.workout_times.each do |time| -%>
<% intensity = "true" %>
<% if time.zone > 1 %>
<% intensity = true %>
<% else %>
<% intensity = false %>
<% end %>
<% if intensity == "true" || @planned_intensity == true %>
<div class="red_dot"></div>
<% end %>
<% end %>
<%= link_to_coaches_dialog workout.activity_id, entry.id.to_s(), "edit", "cal", @athlete.id.to_s, workout.id.to_s(), entry_date.to_date.to_s() %>
<% total_duration = 0 %>
<% completed_workout.workout_times.each do |workout_time| -%>
<% total_duration += workout_time.duration %>
<% end -%>
<% total_planned_duration = 0 %>
<% @planned_times.each do |planned_time| %>
<% total_planned_duration += planned_time.duration %>
<% end %>
<%= time_cleanup(total_duration/60) %>
<% unless total_planned_duration == 0 %>
<span class="smaller"> /
<%= time_cleanup(total_planned_duration/60) %></span>
<% end %>
</li>
<% end -%>
<% end -%>
<% end -%>