私はDeviseのコントローラヘルパーメソッドsigned_inを使用しようとしていますか?ユーザーがすでにサインインしているかどうかを確認し、そうであれば特定のページにリダイレクトします。カスタムセッションコントローラのサインインチェックインの追加方法を教えてください。
私はこれを試しましたが、signed_in?メソッドは常にtrueを返します。どうすればこの作業を行うことができますか?
class SessionsController < Devise::SessionsController
def new
redirect_to root_url
end
def create
if signed_in?(resource_name)
redirect_to where_-_want_to_url
else
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
return sign_in_and_redirect(resource_name, resource)
end
end
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
return render :json => {:success => true, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}
end
def failure
return render :json => { :success => false }
end
end
これは何のために使いますか?ユーザーがログインしているかどうかに応じて、別の**ホームページ**を表示したいだけですか? – Ashitaka
いいえ、ログインページが表示されているが、実際には既にログインしているという状況があるので、服装のリダイレクトをしたい – Rn2dy