[英]Devise authenticate_user redirects to new session path
[英]Devise custom redirects after signup or new session
因此,我有一個RSS提要,其中包含您可以投票的博客帖子,但是首先您必須注冊或登錄才能投票,而我正在使用devise來處理此問題。 我去了這個頁面在這里輸入鏈接描述
以了解如何將其默認重定向更改為request.reffer,即用戶必須登錄或注冊之前所在的當前頁面,但即使將其添加到應用程序控制器后,它仍會重定向回到根目錄:
class ApplicationController < ActionController::Base
protected
def after_sign_in_path_for(resource)
request.env['omniauth.origin'] || stored_location_for(resource) || root_path
end
end
我是Rails和Web開發的新手,所以如果有人可以對我進行白痴驗證,那將不勝感激。 謝謝!
通過將stored_locations_for(resource)設置為nil,您可以走得更遠,然后為每個操作設置不同的重定向,即:after_sign_in_path(resource),after_sign_in_path(resource)等。
devise_for :users, controllers: {sessions: 'users/sessions'}
registrations_controller.rb
class SessionsController < Devise::SessionsController
protected
def after_sign_up_path_for(resource)
example_path
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.