Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - How can you get access to Devise's current_user in the IRB console?

I'm doing some design/debugging in IRB and need to login a user and then be able to use current_user in my efforts.

From Brian Deterling's answer to another question, I have been able to successfully login and access a page response with this sequence:

>> ApplicationController.allow_forgery_protection = false >> app.post('/sign_in', {"user"=>{"login"=>"some-login-id", "password"=>"some-password"}}) >> app.get '/some_other_path_that_only_works_if_logged_in' >> pp app.response.body 

NOTE: If you get a 200 response you are not logged in. You need a 302 redirect to indicate a successful login. See Tim Santeford's answer.

I've been able to get session info:

1.9.3-p125 :009 > app.session  => {"_csrf_token"=>"1yAn0jI4VWzUH84PNTH0lVhjpY98e9echQGS4=", "session_id"=>"89984667d30d0fec71f2a5cbb9017e24"}  

I've tried everything I can think of to try to get to current_user via app and app.session, but no luck. How can I get current_user?

like image 456
Don Leatham Avatar asked Mar 03 '12 07:03

Don Leatham


1 Answers

current_user is a property of the controller so after app.post('/sign_in', ... you can call app.controller.current_user in your rails console to get the User object

like image 185
sguha Avatar answered Sep 28 '22 03:09

sguha