我想在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
答案 0 :(得分:1)
您是否尝试在erb渲染之前使用sleep方法?
答案 1 :(得分:0)
你不能在Ruby中做你想做的事。您应该在一段时间内将HTML添加到可以添加一些javascript或html以重定向的位置。
例如,添加此元标记
<meta http-equiv="refresh" content="1; url=http://example.com/" />
其中1
是秒数