Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails devise: user_signed_in? not working

I have this in my view:

<% if user_signed_in? %>
<%= current_user.email %>
<% else %>
<%= link_to "Sign in", new_user_session_path %><br />
<%= link_to "Opret", new_user_session_path %><br />
<% end %>

But when have signed in as a user: I still get the links in view:

<%= link_to "Sign in", new_user_session_path %><br />
<%= link_to "Opret", new_user_session_path %><br />

Why is the helper not working?

like image 220
John Avatar asked May 14 '11 18:05

John


2 Answers

Did you use devise's before action in your controller?

before_action :authenticate_user!
like image 62
Brian Avatar answered Sep 28 '22 20:09

Brian


Not sure what is behind the user_signed_in? method, either your login is not working correctly or your method is broken.

Maybe try this, if that doesn't work, I would take a look at whats going wrong with the actual login.

<%unless current_user.blank? -%>
signed in
<%else -%>
not signed in
<%end-%>
like image 33
Scott Avatar answered Sep 28 '22 20:09

Scott