2010-12-19 75 views
1

在* user_controller.rb *文件,我有這樣的代碼:使用Prototype,是否有可能「redirect_to」避免處理完整的「js.rjs」代碼?

respond_to do |format| 
    if test = true 
     format.js 
    else 
     format.js { @yo = true } 
    end 
end 

update.js.rjs文件,我有這樣的代碼

page.redirect_to :action => "index" if @yo == true 
page.replace_html... 
... 

這是重定向一個Java性反應的黑客攻擊傳遞一個變量(@yo == true)。不過,我覺得是更好的做這樣的事情「redirect_to的」在大括號避免處理代碼update.js.rjs

respond_to do |format| 
    if test = true 
     format.js 
    else 
     format.js { redirect_to ... } # something example 
    end 
end 

,但我不知道怎麼做,或是否是可能。任何人都可以就這個問題提出建議嗎?

+0

那麼,如果你要重定向,爲什麼不直接用format.html來做呢?你爲什麼使用js重定向? – Andrew 2010-12-19 16:13:35

回答

0

您可以在respond_to塊中使用兩個不同的.js文件。

respond_to do |format| 
    if test = true 
     true.js 
    else 
     false.js 
    end 
end 
相關問題