2013-05-04 58 views
1

我正在使用bootstrap-sass gem,並且出於某種原因導航欄中我正在使用活動類來處理下面的一個li,但它並未按下。爲什麼我的導軌應用程序的引導視圖有趣?

application.html.erb:

<!DOCTYPE html> 
<html> 
<head> 
    <title><%= yield(:title) %></title> 

    <%= stylesheet_link_tag "application", :media => "all" %> 
    <%= javascript_include_tag "application" %> 
    <%= csrf_meta_tags %> 
</head> 
<body id="<%= params[:controller].parameterize %>_controller"> 

<div class="container"> 

    <div class="row"> 
     <div class="span12"> 
      <div class="navbar"> 
       <div class="navbar-inner"> 
       <%= link_to 'evoALL', root_path, 
       html_options = {:class => 'brand'} %> 

       <% navArr = ["Dashboard", "Help People", 
        "Get Help", "Contact Us"] %> 

       <% flash.each do |key, value| %> 
        <p class="lead"><%= value %></p> 
       <% end %> 

       <ul class="nav"> 
        <% navArr.each do |value| %> 
         <li> 

           <a 
           <% if (yield(:navActive)==value) %> 
            class="active" 
           <% end %> 
           href="#"> 
            <%=value%> 
           </a> 

         </li> 
        <% end %> 
       </ul> 
       </div> 
      </div> 
     </div> 
    </div> 


    <%= yield %> 

<div class="container"> 
    <div id="footer"><!-- footer start --> 
     <div class="row-fluid"> 
      <div class="span12"> 
       <p class="pull-right"> 
        &#169; <%= Date.today.year %> 
       </p> 
      </div> 
     </div> 
    </div><!-- footer end --> 
</div> 

</div> <!-- close container div --> 

</body> 
</html> 

index.html.erb對於得以被路由選擇的應用程序的根主控制器的索引方法的視圖文件:

<%= provide(:title, 'evoALL') %> 
<%= provide(:navActive, 'Get Help') %> 
<div class="container"> 
    <div class="row"> 
    <div class="span12"> 
     <p>Needs Home Page</p> 
    </div> 
    </div> 
</div> 

回答

0

我正在將活動類應用到a標籤而不是li標籤。

正確的解決辦法是更換此:

<% navArr.each do |value| %> 

    <ul> 
    <li> 
    <a 
    <% if (yield(:navActive)==value) %> 
     class="active" 
    <% end %> 
    href="#"> 
     <%=value%> 
    </a> 

    </li> 

    </ul> 

<% end %> 

與此:

<ul class="nav"> 
    <% navArr.each do |value| %> 


     <li 
      <% if (yield(:navActive)==value) %> 
       class="active" 
      <% end %>> 
      <a href="#"> 
       <%=value%> 
      </a> 
     </li> 

    <% end %> 
</ul> 
相關問題