抱歉我的英语不好。
麻烦在这里: Miniprofiler向我展示了很多login_path
的请求(导致sessions#new
行动)。虽然Firefox没有显示"此页面没有正确重定向"错误。在Chrome中 - 它只是一遍又一遍地刷新登录页面,直到我手动停止。
我已经获得了带有身份验证的Rails 3.2应用程序(没有设计或其他认证)。在我的ApplicationController中有before_filter :user_authenticated?
(重定向到登录页面,如果没有current_user),我在SessionsController中跳过。
我将 Faye 附加到我的应用程序后出现此问题(两天都没问题,但后来这个奇怪的事情开始了。)
我看过Firebug控制台(Miniprofiler有很多POST请求),我发现theese请求来自 jQuery (8103行未压缩的js)文件 - xhr.send( ( s.hasContent && s.data ) || null );
方法的jQuery.ajaxTransport(function( s ))
。
这是瘦控制台日志:
Started GET "/login" for 127.0.0.1 at 2014-02-07 11:14:25 +0300
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (1.4ms)
Completed 200 OK in 10.7ms (Views: 10.5ms | ActiveRecord: 0.0ms)
Started GET "/login" for 127.0.0.1 at 2014-02-07 11:14:25 +0300
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (1.3ms)
Completed 200 OK in 11.4ms (Views: 11.2ms | ActiveRecord: 0.0ms)
Started GET "/login" for 127.0.0.1 at 2014-02-07 11:14:25 +0300
Processing by SessionsController#new as HTML
Rendered sessions/new.html.haml within layouts/application (5.9ms)
Completed 200 OK in 14.6ms (Views: 14.3ms | ActiveRecord: 0.0ms)
依旧......
我是Rails的新手,所以请帮我解决这个问题。 我已经搜索过类似的问题,但没有找到适合的解决方案。
我还试图评论所有Faye功能和before_filters - 它没有帮助。
UPD:这是我的登录控制器。
class SessionsController < ApplicationController
skip_before_filter :user_authenticated?
def new
end
def create
user = User.find_by_email(params[:email])
if user && user[:account_status] == "blocked"
redirect_to login_path and return
end
if user && user.authenticate(params[:password])
if params[:remember_me]
cookies.permanent[:auth_token] = user.auth_token
else
cookies[:auth_token] = user.auth_token
end
redirect_to character_page_path
else
flash.now.alert = "Invalid email or password"
render "new"
end
end
def destroy
cookies.delete(:auth_token)
redirect_to root_url
end
end
UPD 2:这是我的过滤器。
before_filter :user_authenticated?
def user_authenticated?
unless current_user
redirect_to login_path
end
end
UPD 3:这个问题肯定来自jQuery。也许有些搞砸js需要。 使用rails.jquery和jquery 1.7