如果我在子页面上,我正在尝试在导航项上设置一个活动类。
我现在拥有的是:
module ApplicationHelper
def active_class(link_path)
current_page?(link_path) ? "active" : ""
end
def active_parent_class(link_path)
current_page?(controller: link_path)
end
endactive_class助手可以工作,所以我尝试为父类修改它。我在用:
active_parent_class('sections')在我的菜单上。我的控制器叫做“区段”。因此,基本上,每当我从区段控制器进入任何页面时,我都想在菜单项中添加一个类。
我怎样才能做到这一点?
谢谢,詹姆斯
发布于 2017-05-05 14:05:15
将request.path与输入path进行比较。如果path的一部分也包含在request.path中,那么它也是活动的:
def parent_nav_is_active?(path)
rp=request.path
if rp == path
true
elsif rp.include? path #child page check
true
end
endhttps://stackoverflow.com/questions/43803700
复制相似问题