2017-10-18 92 views
0

我想實現什麼?Spree活動菜單

我想添加一個活動菜單(高亮當前頁面菜單)到我的spree/ruby​​ on rails應用程序。

我試過了什麼?

之後做一些研究,我發現this問題貼非常有幫助,但正如你可能已經猜到了解決方案的實施我found沒有得到我想要的結果。

我發現被添加以下代碼的解決辦法:

守則

application_helper.rb

module ApplicationHelper 

def active_class(link_path) 
    current_page?(link_path) ? "active" : "" 
end 

end 

routes.rb中

root 'spree/home#home' 

    get '/specs', to: 'spree/home#specs' 
    get '/about', to: 'spree/home#about' 
    get '/purchase', to: 'spree/home#purchase' 
    get '/support', to: 'spree/home#support' 

nav.html.erb

<li class="<%= active_class(root_path) %>"> 
<%= link_to "Home", root_path %> 
</li> 

<li class="<%= active_class(purchase_path) %>"> 
<%= link_to "Purchase", purchase_path %> 
</li> 

<li> 
<%= link_to "About", purchase_path %> 
</li> 

<li class="<%= active_class(specs_path) %>"> 
<%= link_to "Technical Details", specs_path %> 
</li> 

<li class="<%= active_class(support_path) %>"> 
<%= link_to 

的錯誤

但現在,不管我去什麼頁面,我得到以下錯誤:

NameError in Spree::Home#purchase 
Showing /home/ubuntu/workspace/mystore/app/views/spree/shared/_nav_bar.html.erb where line #9 raised: 

undefined local variable or method `purchase_path' for #<#<Class:0x007f35a30c6b80>:0x007f35a3642a00> 
Extracted source (around line #9): 


</li> 

<li class="<%= active_class(purchase_path) %>"> 
<%= link_to "Purchase", purchase_path %> 
</li> 

我試着改變幾個變量,但無濟於事

我的問題是

如何創建在狂歡的活動菜單(因爲它是問題的根源)

回答

1

見下面的參考。我已經使用激活而不是主動。你可以風格激活的類此後

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
     <ul class="nav navbar-nav navbar-right" id="link-section"> 
      <li class="<%= 'activated' if current_page?(root_path) %>"> 
       <a href="/">Home 
        <span class="sr-only">(current)</span> 
       </a> 
      </li> 
      <li class="<%= 'activated' if current_page?(new_user_registration_path) %>"> 
       <%= link_to("Register", new_user_registration_path) unless user_signed_in? %> 
      </li> 
      <li class="<%= 'activated' if current_page?(pricing_path) %>"> 
       <%= link_to("Pricing", pricing_path) %> 
      </li> 
      <li class=""> 
       <% if current_user %> 
        <%= link_to("Store", shop_path(current_user.shop)) if current_user.shop.present? %> 
       <% end %> 
      </li> 
      <li class="<%= 'activated' if current_page?(new_user_session_path) %>"> 
       <%= link_to("Login", new_user_session_path) unless user_signed_in? %> 
      </li> 
      <li class="<%= 'activated' if current_page?(dashboard_path) %>"> 
       <%= link_to("Dashboard", dashboard_path) if user_signed_in? %> 
      </li> 
      <li> 

      </li> 
     </ul> 
    </div> 
+0

嗨拉賓,感謝您的迴應!我試過應用你的方法但我一直得到相同的錯誤。看起來瘋狂無法識別我添加到application_helper.rb的代碼 – Salman