I’m adding guest user functionality to my app using the guide detailed in the link here: https://github.com/plataformatec/devise/wiki/How-To:-Create-a-guest-user
I’ve followed these steps and am now trying to access the guest in one of my controllers. Since this controller inherits from ApplicationController, my thought process is I should be able to access the guest_user method like so
@user = guest_user
I’m doing this so I can then show the guest user’s id in my views. I did the skip_before_filter step in the controller method that the above code is inside.
When I try to run this I get the following error: undefined method '[]' for false:FalseClass. I’ve been trying to find the problem but have been unsuccessful.
I tried commenting out the
u.save(false)
and the error became: Couldn't find User without an ID with the accompanying ActiveRecord::RecordNotFound in [controller]. So I believe this means that the problem is occuring in session[:guest_user_id]? Thanks in advance.
I’m using rails 3.1.1, formtastic 2.0.2, and devise 1.5.1
Ok so I solved my own question apparently you have to change
into
I’m not sure why this is the case and the how to guide I linked above did not have this in there so I’ll dig a bit deeper and see if I can find why this is needed for me.
Update: u.save(false) is the outdated version, in rails 3 use u.save(:validate => false)