hol*_*den 7 redirect ruby-on-rails devise omniauth ruby-on-rails-3
我想,如果用户登录后,它会自动重定向到以前的位置,但这似乎永远不会发生,它总是重定向回根位置.从阅读有关设计的文档看来,这个功能似乎只是起作用.我是以某种方式错误地使用它和/或我如何强制它存储位置和重定向无论如何?
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
Run Code Online (Sandbox Code Playgroud)
滚动到此 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
Run Code Online (Sandbox Code Playgroud)
这应该让您可以通过传入“redirect_to”参数来手动创建位置。