Ruby / Rails - 在根页面上隐藏导航栏和页脚
Ruby / Rails - Hide Navbar & Footer on Root Page
我只想隐藏根页面上的导航栏和页脚。我正在使用 RoR。我目前在我的应用程序文件中有我的导航栏以防止重复。我假设我的应用程序控制器上有一个过滤器?
在视图 application.html.erb
中试试这个:
<% unless controller.controller_name == "your_root_controller" && controller.action_name == "your_action" %>
<nav>
#something
</nav>
<% end %>
或者你甚至可以在 helper 中使用这样的方法:
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
我只想隐藏根页面上的导航栏和页脚。我正在使用 RoR。我目前在我的应用程序文件中有我的导航栏以防止重复。我假设我的应用程序控制器上有一个过滤器?
在视图 application.html.erb
中试试这个:
<% unless controller.controller_name == "your_root_controller" && controller.action_name == "your_action" %>
<nav>
#something
</nav>
<% end %>
或者你甚至可以在 helper 中使用这样的方法:
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