0

I'm trying to find out where to set a session variable once a user has logged in using Devise. I found this post (and others):

Set a session variable in devise on sign in

So I tried something like this:

protected
    # when a user logs in
    def after_sign_in_path_for(resource_or_scope)
      session[:current_account_id] = current_user.accounts.find_by_is_default(true).id # get id of row where it's is_default is set as true
      abort(session[:current_account_id])
    end

..but no joy. I don't want to do an alternative redirect (as the issue in the link was asking), just set a session variable when the user logs in, so I'm not sure if this is the callback I'm wanting. Also, I may have my find_by_ method wrong but I was hoping I could debug (using abort) once the script gets that far - but it doesn't appear to be as abort doesn't seem to be called. Any help much appreciated. Thanks

Community
  • 1
  • 1
Martyn
  • 6,031
  • 12
  • 55
  • 121

1 Answers1

0

Make sure the protected method is located inside of ApplicationController.

Yosep Kim
  • 2,931
  • 22
  • 23