Thursday 15 August 2013

Show different menu items for logged in user in Rails -


I try to create a menu bar in my Rail app to show a login to a user bar I am not logged in, and logout plus what work they have, i.e. admin , user , etc. I tried to use this code in my application layout ( application.html.haml in app / view / layout )

  % Ul {: class = & gt; 'Nav'}% li = link_to 'Home' ,: root - if logged_in? However, it gives me an error telling me,  
  nonpropriate in session # New undefined method 'login_'? # & Lt; # & Lt; For Class: 0x007f771bbe0f70>: 0x007f771bc6a1a8 & gt;   

I do not have to change anything in layout other than the menu, so I do not want to render different layouts, if a user is logged in. Is it possible to logged_in? to show the method in the applications layout, or in any way, whether a user is logged in or not?

user_signed_in?

Edit: P>

Controlling methods can be said only to controllers, however, you can store the result of that method in an example variable . In your ApplicationController,

  before_filter: login_check def login_check @logged_in = logged_in? Finally, in your opinion, you can see whether the @logged_in is true, such as  
 % ul {: class = & gt; 'NAV'}% li = link_to 'Home' ,: root - if @logged_in% li = link_to 'logout', logout_url    

No comments:

Post a Comment