私はHartlチュートリアルに基づいたプロジェクトを進めています。私は、動作するユーザー認証モデルをセットアップしました...ほとんど。ユーザーはサインアップできますが、sign_inプロセスに問題があります。ユーザーがサインアウトした場合、サインインすることは不可能です。データベースがユーザーのサインアップ情報を保存していることを確認しました。問題は、ユーザーがサインアップしたことを確認することです。私は自分のログを見てきたが、役に立たない。Railsアプリはユーザーを覚えておらず、再度サインインすることができます
Started POST "/sessions" for 127.0.0.1 at 2012-04-15 13:56:46 -0500
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"itOIPKPrXlymcBujKMu4Xjwvs6GlD3jteBQJf+/mYEY=", "session"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Sign in"}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = '[email protected]' LIMIT 1
Rendered sessions/new.html.erb within layouts/application (1.6ms)
Rendered layouts/_stylesheets.html.erb (2.0ms)
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
Rendered layouts/_header.html.erb (3.2ms)
Rendered layouts/_footer.html.erb (0.3ms)
Completed 200 OK in 30ms (Views: 16.1ms | ActiveRecord: 2.6ms)
しかし、私が見るべきことはこれです:
これは私が得るものです。
Started POST "/sessions" for 127.0.0.1 at 2012-04-15 12:50:24 -0500
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"h/M5VYBaG16sGiGHTWo26GJSU1/TlMNFjQd5TN1VZ3Y=", "session"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Sign in"}
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = '[email protected]' LIMIT 1
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = '[email protected]' LIMIT 1[0m
Redirected to http://localhost:3000/users/103
Completed 302 Found in 19ms
私の質問は以下のとおりです。 この問題をトラブルシューティングについて移動する最良の方法は何ですか?
私はどこから見始めなければならない "明白な"場所は何ですか?私はここにあるユーザー認証コードを使用しています。私は他のプロジェットでもそれを実装しました。それは私に問題を与えているのはこれだけです。 ここに私の認証コードです。
module SessionsHelper
def sign_in(user)
cookies.permanent.signed[:remember_token] = [user.id, user.salt]
self.current_user = user
end
def current_user=(user)
@current_user = user
end
def current_user
@current_user ||= user_from_remember_token
end
def signed_in?
current_user.present?
p "user signed_in? method called"
p current_user
end
def sign_out
cookies.delete(:remember_token)
self.current_user = nil
p "user has signed out" #Method does NOT get called
end
def current_user?(user)
user == current_user
end
def authenticate
deny_access unless signed_in?
end
def deny_access
store_location
redirect_to signin_path, :notice => "Please sign in to access this page."
end
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
clear_return_to
end
private
def user_from_remember_token
p "Looking user up from the cookie"
User.authenticate_with_salt(*remember_token)
end
def remember_token
cookies.signed[:remember_token] || [nil, nil]
end
def store_location
session[:return_to] = request.fullpath
end
def clear_return_to
session[:return_to] = nil
end
end
Cool。例外を提起していただきありがとうございます。 –