我想在erb answerdoorno上等几秒钟,然后它会重定向到警方。我该如何做到这一点。。。。
post '/answerdoor' do
answerdoor = params[:door]
door = rand(2).floor
if answerdoor.include?('yes') && door == 0
erb :answerdoor, :locals => {:answerdoor => "You Decide to get up and answer the door", :answerdoor2 => " You are in Luck It's Your good buddy Dave." }
elsif answerdoor.include?('yes') && door == 1
erb :answerdoor, :locals => {:answerdoor => "You Decide to get up and answer the door", :answerdoor2 => " Oh No its The cops." }
redirect to ('/police')
elsif answerdoor.include?('no') && door == 0
erb :answerdoorno, :locals => {:answerdoor => "You Decide not to answer the door, but it dosen't Really matter cause Dave walks in anyways."}
elsif answerdoor.include?('no') && door == 1
erb :answerdoorno, :locals => {:answerdoor => "You Decide not to answer the door, but it dosen't Really matter cause its the cops and the bust in."}
redirct to ('/police')
end
end
在erb渲染之前,您是否尝试过使用sleep方法?
http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-sleep
在Ruby中你不能随心所欲。您应该在HTML中添加一些javascript或HTML,以便在一秒钟或更长时间后重定向。
例如,添加这个元标签
<meta http-equiv="refresh" content="1; url=http://example.com/" />
其中1
是秒数