【发布时间】:2017-10-18 15:01:15
【问题描述】:
我想达到什么目标?
我正在尝试向我的 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>
我尝试更改了几个变量,但都无济于事
我的问题是:
我如何在 Spree 中创建一个活动菜单(因为它是问题的根源)
【问题讨论】:
标签: ruby-on-rails ruby spree