简体   繁体   中英

How to set a session variable after sign in with Devise?

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

确保受保护的方法位于ApplicationController内部。

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