1
我正在使用康康和設計。我有以下所以當cancan錯誤重定向頁面登錄路徑:設計:登錄後重定向回到cancan保護路徑
check_authorization :unless => :devise_controller?
rescue_from CanCan::AccessDenied do |exception|
redirect_to new_user_session_path, :alert => exception.message
end
這很好。但是,我希望能夠在用戶登錄後將其重定向回Cancan保護的頁面。
我在此處使用Devise wiki中的腳本(How To: redirect to a specific page on successful sign in)。
def after_sign_in_path_for(resource)
sign_in_url = url_for(:action => 'new', :controller => 'sessions', :only_path => false, :protocol => 'http')
if request.referer == sign_in_url
# this path is used
super
else
stored_location_for(resource) || request.referer || root_path
end
end
但這總是會使用super
方法,都到索引頁。我做錯了什麼?
更常用的解決方法是:http://stackoverflow.com/questions/26543503/redirect-back-to-current-page-using-omniauth -and-色器件 – lulalala