CancanとDeviseの両方を使用しています。私は以下を持っているので、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 のスクリプトを使用します (方法: サインインが成功したときに特定のページにリダイレクトする)。
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
インデックスページに移動するメソッドを使用します。私は何を間違えましたか?