辛纳特拉地图绘制路线
所有,我需要按照以下方式执行此操作,
require 'sinatra'
require 'app_env'
get '/home' do
'home page'
end
get '/about' do
'about page'
end
get '/docs' do
'docs page'
end
我不确定哪条路线将是根路线,可能是主页、关于或文档页面。因此,我必须在文件 app_env.rb 中使用这样的行设置根页面 route_map '/home' => '/'
。 现在,我如何编写方法/函数 route_map
或其他任何内容来实现动态映射路线的要求。
编辑:我的答案
HOMEPAGE = '/home_page'
get '/' do
status, headers, body = call! env.merge("PATH_INFO" => HOMEPAGE)
end
all, i need to do this as the following
require 'sinatra'
require 'app_env'
get '/home' do
'home page'
end
get '/about' do
'about page'
end
get '/docs' do
'docs page'
end
I not sure which route will be the root route, maybe the home, about, or docs page. So, i have to set the root page in a file app_env.rb with a line like this route_map '/home' => '/'
.
Now, how do i write the method/function route_map
or anything else to implement my requirement for mapping the route dynamically.
EDIT : MY ANSWER
HOMEPAGE = '/home_page'
get '/' do
status, headers, body = call! env.merge("PATH_INFO" => HOMEPAGE)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望将“/”的请求重新路由到“/home”,那么您需要做的就是:
如果您不想重定向,可以执行以下操作:
请参阅 此了解详细信息。
If you are looking to reroute requests for '/' to '/home' then all that you need to do is:
If you do not want to redirect you could do this:
See this for details.