Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Its bad idea, to raise exception, if no "User" found with such id #365

wants to merge 1 commit into from

3 participants


For example, u logged, on the site, then destroy your auth model(User for simplicity),
if user try go to website, rails will render 500 error, cause find raise exception "No record found",
better user experience is just redirect to not_authenticated path.


I respect this commit NoamB/sorcery@228cf83 but actually I don't know mongoid

login_from_session method don't raise exception because it is rescued.


I agree with @kuboon that ActiveRecord::RecordNotFound which can be thrown from find will be rescued anyway (

@kirs kirs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/sorcery/controller.rb
2  lib/sorcery/controller.rb
@@ -112,7 +112,7 @@ def login_from_other_sources
def login_from_session
- @current_user = (user_class.find(session[:user_id]) if session[:user_id]) || false
+ @current_user = (user_class.where(:id =>session[:user_id]).first if session[:user_id]) || false
rescue => exception
return false if defined?(Mongoid) and exception.is_a?(Mongoid::Errors::DocumentNotFound)
return false if defined?(ActiveRecord) and exception.is_a?(ActiveRecord::RecordNotFound)
Something went wrong with that request. Please try again.