关于n秒后跳转google上很多文章,讲的很详细了
这里主要还是使用meta来实现
直接照下面这样写就可以了
render :text=>'<meta http-equiv="refresh" content="3; url=/welcome"> 3s refresh'?
如果需要这里我们写个helper来做这个事情#创建一个helper
>ruby script\generate helper c_http
#编辑helper内容如下,这里主要使用了 eval 方法
>type app\
helpers\c_http_helper.rb
module CHttpHelper
??def auto_redirect(arg={})
????sec = arg[:sec] || 3
????url = arg[:url] || '/'
????msg = arg[:msg] || ''
????msg += " Redirect to '#{url}' after #{sec} sec"
????eval("render :text=>\"<meta http-equiv='refresh' content='#{sec}; url=#{url}
'>#{msg}\"")
??end
end
#在controller中使用helper
class SessionsController < ApplicationController
??include CUserAuthenticationHelper
??include CHttpHelper
??def new
????userid = params[:userid]
????passwd = params[:passwd]
????if authenticate(userid,passwd)
??????...
????else
??????auto_redirect(:sec=>'5',:url=>welcome_path,:msg=>'sql query error')
????end
??end
??...
end