狂欢活动菜单
Spree active menu
我想达到什么目的?
我正在尝试将活动菜单(在菜单中突出显示当前页面)添加到我在 rails 应用程序上的 spree/ruby。
我尝试了什么?
经过一些研究,我发现 this question posted very helpful, but as you might have guessed the implementation of the solution I 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>
我试过更改几个变量,但无济于事
我的问题是:
如何在 Spree 中创建活动菜单(因为这是问题的根源)
请参阅下面的参考资料。我使用激活而不是激活。您可以在
之后设置激活的 class 样式
<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>
我想达到什么目的?
我正在尝试将活动菜单(在菜单中突出显示当前页面)添加到我在 rails 应用程序上的 spree/ruby。
我尝试了什么?
经过一些研究,我发现 this question posted very helpful, but as you might have guessed the implementation of the solution I 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>
我试过更改几个变量,但无济于事
我的问题是:
如何在 Spree 中创建活动菜单(因为这是问题的根源)
请参阅下面的参考资料。我使用激活而不是激活。您可以在
之后设置激活的 class 样式<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>