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
Ruby 1.9.2 How to Install Rmagick on Windows
Include Jekyll/Liquid Template Data in a Yaml Variable
Why Does Ruby'S 'Gets' Includes the Closing Newline
Installing Jekyll Without Root
How to Calculate the Day of the Week of a Date in Ruby
Rails 3.1 Limit User Created Objects
Class ≪≪ Self VS Self.Method With Ruby: What's Better
When Do I Need to Restart Server in Rails
Really Cheap Command-Line Option Parsing in Ruby
Read Binary File as String in Ruby
How to Run Rake Tasks Within a Ruby Script
One-Liner to Recursively List Directories in Ruby
How to Check If a Ruby Object Is a Boolean
Bundler Not Working with Rbenv, Could Not Find [Gem]
Ruby on Windows Causes Error Cannot Load Such File Bcrypt_Ext