8

我希望它在用户登录后自动重定向到他们以前的位置,但这似乎永远不会发生,它总是重定向回根位置。通过阅读为此设计的文档,似乎该功能应该可以正常工作。我是否以某种方式错误地使用它和/或如何强制它存储位置并无论如何重定向?

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
4

1 回答 1

4

滚动到此 Google 群组页面的底部并查看覆盖的“stored_location_for”设计方法。我的 application_controller 中有一个改编版本,如下所示:

  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

这应该让您通过传入“redirect_to”参数来手动创建位置。

于 2010-12-02T07:11:20.587 回答