Rails Devise: User_Signed_In? Not Working

User signed in, but set to nil using Rails and Devise

Solution:
my current_user method in the application controller was overriding devise's own current_user method. I removed the current_user method I had in my application controller and it now shows:

current_user :#<User id: 2, email: "test@tester.com", username: "", admin: false, created_at: "2018-01-07 20:09:17", updated_at: "2018-01-07 21:33:51">
session id request :all
user_signed_in? :true
current user present? :true

found answer here: devise - can't display sign in or sign out in rails view

Rails, Devise: If user signed in create with user id, else without

It's quite simple, you can use user_signed_in? helper:

if user_signed_in?
@stream = current_user.streams.build(params[:name])
else
@stream = Stream.new(params[:name])
end

BTW make sure you pass valid params while building object.

How can I check if user is signed in with rails devise?

First of all remove do from this line, you don't need that

<% if user_signed_in? %>

Secondly add : after method, it's a key value pair

<%= link_to "Log out", destroy_user_session_path, method: :delete %>

Hope that helps!

Keep User Signed in with Devise

Found the answer on SO here

For whatever reason, the default rails.js killed the session whenever a .js call was made. The solution is to update rails.js (from here).



Related Topics



Leave a reply



Submit