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
,但我不知道怎么做,或是否是可能。任何人都可以就这个问题提出建议吗?
那么,如果你要重定向,为什么不直接用format.html来做呢?你为什么使用js重定向? – Andrew 2010-12-19 16:13:35