sinatra停止从公共文件夹加载文件

时间:2012-07-06 03:18:58

标签: ruby sinatra settings

我设置了公共文件,它工作正常,但突然间sinatra停止从公共文件夹加载文件, 我在尝试加载css和javascript文件时得到404 这是我的配置

    set :root, File.dirname(File.dirname(__FILE__))
    set :views, File.dirname(__FILE__) + "/../views"
    set :public_folder, File.dirname(__FILE__) + "/../public"

更新:

当我的代码

时会发生这种情况
    get '/' do
        if Sources.all.size>0 then
            haml :home, {:layout => :"home-layout"}
        elsif request.ip == "127.0.0.1" then
            redirect '/setup/sources'
        else
            redirect '/nothing-here'
        end             
    end 

    get '/setup/sources' do
        if Sources.all.size == 0 then
            @list=FOps.ls(Dir.home).to_json
            haml :setup, {:layout => :"nosetup-layout"}
        else
            redirect '/setup/files'
        end
    end

它只能用/ setup / sources才能正常使用/

当我替换代码时

    get '/' do
        if 0 < 1 then
            haml :home, {:layout => :"home-layout"}
        elsif request.ip == "127.0.0.1" then
            redirect '/setup/sources'
        else
            redirect '/nothing-here'
        end             
    end 

    get '/setup/sources' do
        if 0 < 1 then
            @list=FOps.ls(Dir.home).to_json
            haml :setup, {:layout => :"nosetup-layout"}
        else
            redirect '/setup/files'
        end
    end

它不会加载js和css localhost:4567 / setup / sources但它在localhost上加载正常:4567

1 个答案:

答案 0 :(得分:0)

问题出在相对路径上,在使用根路径

后修复了问题