此操作无效:
redirect_to request.referer, :format => "html", :alert => exception.message
当它从 js 格式的控制器操作重定向时,重定向也是 js 格式,而不是 html 格式。
任何线索为什么?谢谢!
PS:我也试过 :format => :html
编辑完整性
重定向发生在通过此 application_controller 方法进行 cancan 自动化之后
if request.referer
logger.debug "Rescueing Cancan"
redirect_to request.referer, :format => :html, :alert => exception.message
else
redirect_to root_path, :alert => exception.message, :format => :html
end
end
这是我的日志:
Started GET "/challenges/ground-floor/tasks" for 127.0.0.1 at 2012-12-06 11:17:06 +0100
Processing by ChallengesController#tasks as JS
Parameters: {"id"=>"ground-floor"}
Projectmilestone Load (0.6ms) SELECT "projectmilestones".* FROM "projectmilestones" WHERE "projectmilestones"."id" = 790 LIMIT 1
Rescueing Cancan
Redirected to http://127.0.0.1:3000/challenges/ground-floor?subaction=pmdocuments&page=1
Completed 302 Found in 105ms (ActiveRecord: 1.6ms)
Started GET "/challenges/ground-floor?subaction=pmdocuments&page=1" for 127.0.0.1 at 2012-12-06 11:17:06 +0100
Processing by ChallengesController#show as JS