2017-05-05 64 views
1

我想設置一個導航項目上的活動類,如果我在子頁面上。Ruby on rails parent nav active

這是我有:

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 
end 

的active_class輔助工作,所以我試圖修改它的父類。我正在使用:

active_parent_class('sections') 

在我的菜單中。我的控制器被稱爲「部分」。所以基本上任何時候我都在部分控制器的任何頁面中,我想添加一個類到菜單項。

我該如何做到這一點?

謝謝, 詹姆斯

回答

0

比較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 
    end