此操作不起作用:
redirect_to request.referer,:format => “html”,:alert => exception.message
当它以js格式从控制器动作重定向时,重定向也是js,而不是html格式。
有什么线索的原因? THX!
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
答案 0 :(得分:2)
尝试使用
中的:back
redirect_to :back, alert: exception.message
来自redirect_to
上的文档:
的简写
:back
- 返回发出请求的页面。适用于从多个位置触发的表单。redirect_to(request.env["HTTP_REFERER"])