需要一些建议,我知道直接在视图中分配变量是一种不好的做法。但我发现只有一种方法可以实现引导程序'nav-tab'。可能有其他方法吗?谢谢
<div class="tabbable tabs-left">
<ul class="nav nav-tabs">
<% answer = [] %> // Here it is..
<% @questions.each_with_index do |question, index| %>
<li class="<%= "active" if index == 0 %>">
<a href="#pane<%= index + 1 %>" data-toggle="tab">
<%= question.title %>
</a>
</li>
<% answer << [index, question]%>
<% end %>
</ul>
<div class="tab-content">
<% answer.each do |i, a| %>
<div id="pane<%= i + 1 %>" class="tab-pane <%= 'active' if i == 0 %>">
<div class="links">
<%= link_to '', edit_question_path(a), class: "icon-pencil" %>
<%= link_to '', a, method: :delete, data: { confirm: 'Are you sure?' }, class: "icon-remove" %>
</div>
<%= raw a.content %>
</div>
<% end %>
</div><!-- /.tab-content -->
</div><!-- /.tabbable -->