2016-09-06 36 views
0

我想僅在根頁面上隱藏導航欄和頁腳。我正在使用RoR。我目前在我的應用程序文件中有我的導航欄以防止重複。我假設我的應用程序控制器上有一個過濾Ruby/Rails - 在根頁面上隱藏導航欄和頁腳

+1

[如何檢測是否導軌是在根URL](http://stackoverflow.com/questions/1924620/how-to-detect-if-rails-is -at-the-root-url) – Mick

回答

0

鑑於application.html.erb試試這個:

<% unless controller.controller_name == "your_root_controller" && controller.action_name == "your_action" %> 
    <nav> 
     #something 
    </nav> 
<% end %> 

,甚至你可以在輔助性的東西的方法是這樣的:

def root? 
controller.controller_name == "your_root_controller" && controller.action_name == "your_action" 
end 

,並鑑於application.html.erb未來:

if root? 
    #something html 
end 

或您也可以使用current_page?方法,並以這種方式:

鑑於

application.html.erb

if current_page?(root_path) 
    # your html 
end 
+0

讚賞多種解決方案。你會推薦一個特定的生產用途嗎? –

+0

如果只有root用戶,我推薦你用'current_page?'方法解決上一個問題 –