简体   繁体   中英

Devise with Rails 2.3.8 produces deserialize error after manual sign_in of a user

I'm using Devise 1.0.11 with Rails 2.3.8. I have a setup where I want to login a user automatically through a controller action looking like this

def select_private
   reset_session
   private_user = User.find_by_identifier "PRIVATE"
   sign_in :user, private_user
   redirect_to a_page_that_needs_authentication_of_a_user_url
end

the test for this looks like this and runs just fine

test "select the private customer" do
   get '/'
   assert_response :success
   get_via_redirect '/select/private'
   assert_response :success
   assert_equal path, '/shirt'
end

But when I am trying this out on my local Mongrel server I get an MethodNotFound error

undefined method `find' for Symbol:Class

after the redirect to the page_that_needs_authentication_of_a_user with the following stack trace of the last few interesting lines

gems/devise-1.0.11/lib/devise/rails/warden_compat.rb:23:in `deserialize'
gems/ruby-1.8.7-p302@rails2/gems/warden-1.0.3/lib/warden/session_serializer.rb:31:in `fetch'
gems/warden-1.0.3/lib/warden/proxy.rb:182:in `user'
gems/warden-1.0.3/lib/warden/proxy.rb:270:in `_perform_authentication'
gems/warden-1.0.3/lib/warden/proxy.rb:113:in `authenticate!'
gems/devise-1.0.11/lib/devise/controllers/helpers.rb:207:in `authenticate_user!'

The action that is rendered calls the authenticate_user, as a before_filter. working great when accessed through the normal Session#new login form.

Could this be a bug, or do you have any other ideas?

Simple solution. If you have the same problem your private_user is probably nil.

private_user.nil? => true

My test data included a user for that identifier, the development database not. I already offered to submit a patch with a meaningful error message as this one is pretty misleading, in my view.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM