Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devise sign_in_and_redirect never seems to work

I would like it, if after a user logs in, that it automatically redirect to their previous location, but this never seems to happen, it always redirects back to the root location. From reading the docs on devise for this it seems this functionality is supposed to just work. Am I using it somehow wrongly and/or how can I force it to store the location and redirect regardless?

http://rubydoc.info/github/plataformatec/devise/master/Devise/Controllers/Helpers#stored_location_for-instance_method

authentication = UserToken.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])

if authentication
  flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => omniauth['provider']
  sign_in_and_redirect(:user, authentication.user)
else
like image 202
holden Avatar asked Nov 20 '10 19:11

holden


1 Answers

Scroll to the bottom of this Google group page and check out the overridden 'stored_location_for' devise method. I have an adapted version of it in my application_controller that looks like this:

  def stored_location_for(resource)
    if current_user && params[:redirect_to]
      flash[:notice] = "Congratulations, you're signed up!"
      return params[:redirect_to]
    end
    super( resource ) 
  end

That should let you create the location manually by passing in a 'redirect_to' param.

like image 186
John McGrath Avatar answered Sep 27 '22 16:09

John McGrath