简体   繁体   中英

devise 'user_path' error when redirecting after log-in

I used this code block in devise,from https://coderwall.com/p/djgkag , to return the users where they came from after a successful login:

def after_sign_in_path_for(resource_or_scope)
  session.fetch 'user_return_to', user_path
end

But i get an error that says:

NameError in SessionsController#create undefined local variable or method `user_path' for #

How will I define user_path? or how will i replace it? I've run rake routes and its not there indeed.

You could try and do the following:

def after_update_path_for(resource)
  session[:return_to] ||= request.referer
end

With this you can then call this in your controller by doing redirect_to session[:return_to] . If that does not work, take a look at How To: Redirect back to current page after sign in, sign out, sign up, update . Which should detail what your after. But try the way I suggested first.

Maybe you should redirect to edit_user_registration_path.

Devise does not provide any profil page by default.

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