2

假设我的目录结构类似于:

path_to_file/one/index.html

如何将我的 sinatra 应用程序设置为路由到

mysite.com/path_to_file/one/

并有前面提到的文件来渲染?path_to_file将始终保持不变,但其中会有不同的文件夹(twothree等)。

我尝试了以下方法:

get '/path_to_file/:number' do
  File.read(File.join('path_to_file', "#{params[:number]}", "index.html"))
end

但随后链接自的例如 javascript 文件index.html无法正确呈现。

4

2 回答 2

2

知道了!

get '/path_to_file/:number/:file' do
  File.read(File.join('path_to_file', "#{params[:number]}", "#{params[:file]}"))
end

get '/path_to_file/:number' do
  File.read(File.join('path_to_file', "#{params[:number]}", "index.html"))
end

顺序很重要,因为如果这两种方法颠倒过来,get '/path_to_file/:number'就会变成get '/path_to_file/:number/:file'.

于 2011-05-01T00:58:59.253 回答
0

只是一个想法,但您可以设置您的服务器软件Apache,,,,nginx无论您使用的是什么,以从不同的位置提供和图像文件.css.js

于 2011-04-30T04:28:43.013 回答