我想知道如何在注册和登录页面上隐藏菜单。我得到了这个代码。问题是Devise gem没有控制器,我可以隐藏菜单。那么,最好的方法是什么?
application.html.haml
- if user_signed_in?
%nav.navigation
%ul
%li
= link_to "New project", new_place_path
%li
= link_to "Profile"
%li
= link_to "Sign Out", destroy_user_session_path, method: :delete
- else
%nav.navigation_welcome
.inner
%ul
%li
= link_to "Login", new_user_session_path
%li
= link_to "Sign up", new_user_registration_path
对于注册\登录,我使用设计。
答案 0 :(得分:1)
您可以按照here所述覆盖设计控制器。在那里,您可以指定不包含导航栏的布局
或者如果您只想处理视图图层,可以查看controller_name
:
- if user_signed_in?
%nav.navigation
%ul
%li
= link_to "New project", new_place_path
%li
= link_to "Profile"
%li
= link_to "Sign Out", destroy_user_session_path, method: :delete
- elsif include_navbar?
%nav.navigation_welcome
.inner
%ul
%li
= link_to "Login", new_user_session_path
%li
= link_to "Sign up", new_user_registration_path
然后在你的应用程序助手中:
def include_navbar?
controller_name != 'sessions' && controller_name != 'registrations'
end