2012-12-06 38 views
2

這個動作不起作用:軌redirect_to的HTML格式不起作用

redirect_to的request.referer,:格式=> 「HTML」:警惕=> exception.message

當它從重定向一個js格式的控制器動作,重定向也在js中,而不是html格式。

任何線索爲什麼?謝謝!

PS:我嘗試:格式=>:HTML以及

EDIT出於完整性

重定向從這個application_controller方法

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 

一個康康舞autorization之後發生這是我日誌:

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 

回答

2

嘗試使用:back

redirect_to :back, alert: exception.message 

從文檔上redirect_to

:back - 返回發出請求的頁面。對於從多個地方觸發的表單很有用。短片爲redirect_to(request.env["HTTP_REFERER"])

+0

謝謝你的提示,我不知道。但它不能解決我的問題...... :-(我編輯了完整性答案 – ndemoreau