2010-11-20 84 views
7

我希望它,如果用戶登錄後,它會自動重定向到他們以前的位置,但這似乎永遠不會發生,它總是重定向回到根位置。從閱讀關於這個設計的文檔看來,這個功能應該是可行的。我是否以某種方式錯誤地使用它和/或我如何強制它存儲位置並重定向?devise sign_in_and_redirect似乎永遠不會工作

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 
+0

我剛剛意識到我沒有得到默認功能,因爲我沒有使用authorize_user!存儲位置的回調...所以我如何手動創建位置? – holden 2010-11-20 19:41:53

+0

你是怎麼解決這個問題的?我正在關注https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview,以將Devils的rails 3.2.5應用程序的facebook登錄集成在一起。 sign_in_and_redirect方法不起作用:( – asitmoharna 2012-06-16 14:33:03

+0

我有同樣的問題,只做了一個手動sign_in和一個單獨的重定向,請檢查sign_in_and_redirect的源代碼 sign_in @user redirect_to root_path – MatthewFord 2012-09-16 22:56:10

回答

4

滾動到的this Google group page底部,並檢查了重寫 '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的」 PARAM創建的位置。