Ruby 如何使用Rack执行HTTP重定向(302)?
我正在摆弄我的第一个机架应用程序(这只是为了实验) 当接到电话时,我会这样做:Ruby 如何使用Rack执行HTTP重定向(302)?,ruby,http,rack,Ruby,Http,Rack,我正在摆弄我的第一个机架应用程序(这只是为了实验) 当接到电话时,我会这样做: class Application def call(env) # Totally ignore favicons for the time being if env['PATH_INFO'] == '/favicon.ico' return [ 404, {'Content-Type' => 'text/html'}, [] ] elsif env[
class Application
def call(env)
# Totally ignore favicons for the time being
if env['PATH_INFO'] == '/favicon.ico'
return [ 404, {'Content-Type' => 'text/html'}, [] ]
elsif env['PATH_INFO'] == '/'
return [ 302, {'http-equiv' => "refresh", 'content' => "2;url=http://google.com"}, [] ]
end
...
我知道这很可怕。。。但是,这又不是一个严肃的项目
我在想怎么做重定向。我所拥有的不起作用。基本上,当你在我的网站上点击/时,我想将这一要求重定向到google.com。这里有一个与re direct to google一起工作的应用程序
require 'rack'
require 'rack/server'
class HelloWorld
def response
[ 302, {'Location' =>"http://google.com"}, [] ]
end
end
class HelloWorldApp
def self.call(env)
HelloWorld.new.response
end
end
Rack::Server.start :app => HelloWorldApp
这是一个与re direct to Google一起工作的应用程序
require 'rack'
require 'rack/server'
class HelloWorld
def response
[ 302, {'Location' =>"http://google.com"}, [] ]
end
end
class HelloWorldApp
def self.call(env)
HelloWorld.new.response
end
end
Rack::Server.start :app => HelloWorldApp
程序中缺少两个
end
。如果没有这些,它就不能编译。我不想让它可以编译(无论如何,你不能单独测试它)。我的意图是表示有使用省略号的省略代码。您的程序中缺少两个end
。如果没有这些,它就不能编译。我不想让它可以编译(无论如何,你不能单独测试它)。我的意图是表示有省略代码使用省略号。