环境:ruby1.8.7, rails 2.2.2
单词写错引发的悲剧
class ApplicationController < ActionController::Base
layout "store"
before_filter :authorize, :except => :login
end
误将except写成expect,发送login的请求时,浏览器就卡住不动了,开始还怀疑是rails性能问题,但也不至于直接挂了吧?
也没有提示任何错误信息,找到develpment.log文件一看
Processing AdminController#login (for 127.0.0.1 at 2012-05-06 18:37:18) [GET]
Session ID: 977a670981cd9b78e579f52fa8b2f9d6
Parameters: {"action"=>"login", "controller"=>"admin"}
[4;35;1mUser Load (0.000000)[0m [0mSELECT * FROM users WHERE (users."id" IS NULL) LIMIT 1[0m
Redirected to http://127.0.0.1:3000/admin/login
Filter chain halted as [#<ActionController::Filters::ClassMethods::SymbolFilter:0x3e96d8c @filter=:authorize>] rendered_or_redirected.
Completed in 0.01500 (66 reqs/sec) | DB: 0.00000 (0%) | 302 Found [http://127.0.0.1/admin/login]
Filter chain halted? 什么情况,不清楚,开始怀疑是这个过滤器写得有问题
def authorize unless User.find_by_id(session[:user_id]) session[:original_uri] = request.request_uri flash[:notice] = "Please Log In" redirect_to :controller => 'admin', :action => 'login' end end
根据提示信息,Filter chain halted as[......]rendered_or_redirected. 错误的认为是重定向这句错了,结果调了2个小时,百度,谷歌,没有找到好的解决办法,受不了了,上QQ求助,无解
抽根烟~~, 我靠,except写成expect了,修改后没问题了
有一点没有想清楚, 修改之前程序确实是走到了authorize里面, 就是不执行重定向这句,请高人指点~