I am building an app with two pretty separate models both using devise for auth. Once you sign in as a house, then each individual in the house can sign in as a resident of that house. Everything is working fine except that when i log out of a resident session using
destroy_resident_session
the only problem with this is that it also kills the house session since it calls
Devise::SessionsController#destroy
I have tried to create a custom session for residents, here is my code below:
class SessionsController < Devise::SessionsController
# DELETE /resource/sign_out
def destroy
redirect_path = after_sign_out_path_for(resource_name)
signed_out = sign_out(resident)
set_flash_message :notice, :signed_out if signed_out && is_navigational_format?
# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.all { head :no_content }
format.any(*navigational_formats) { redirect_to redirect_path }
end
end
end
This gives an error:
undefined local variable or method `resident'
I may be misunderstanding the method logic but it seems like i want to change the following line in the devise sessions controller:
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
Since I do not want to sign out of all scopes, only the resident scope.
Solved
All I had to do was set
config.sign_out_all_scopes = false
in
config/devise.rb
And also, had to remember to restart my server :)
This should be marked as the answer. You did not post it but I had the same issue and that was the solution so I am posting it for the community
config/devise.rb
config.sign_out_all_scopes = false
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.