2011-02-05 61 views
2

我正嘗試在機架中使用機架離線使我的網頁可脫機。默認情況下,機架脫機會將公用文件夾中的所有文件放入緩存清單中。我應該在哪個文件中進行更改,以便將需要的文件添加到緩存清單中。我想將文件包含在我的視圖文件夾中。如何更改機架離線的默認行爲

回答

0

沒有服務器,視圖文件夾中的任何文件都不可用。你想在緩存清單中創建一個可用的路由?例如「/ about」,例如對應於「views/about.haml」文件?

添加到您的配置:

offline = Rack::Offline.configure do 
    cache "about" # or whatever your route is 
    public_path = Rails.public_path 
    Dir[public_path.join("javascripts/*.js")].each do |file| 
    cache file.relative_path_from(public_path) 
    end 
end 
+0

在哪個文件我是想添加這個代碼 – rdp 2011-02-05 16:29:04

+0

您的環境配置文件可能? – stef 2011-02-05 21:18:50

7

你需要將它添加到您的routes.rb文件。這是我的routes.rb文件與定製清單。這將爲您提供索引和新路線以及公共根(* .html)中的所有html文件以及子文件夾中的每個文件公開(*/*。*)。你可以切片和骰子,但是你需要它在公用文件夾中的東西。

我不知道如何獲取數據庫特定的路線,如離線時顯示和編輯。我會想像Javascript是需要的。退房Railscast episode 248的一些想法整合JS

OfflineConfirm::Application.routes.draw do 
    #match '/application.manifest' => Rails::Offline 
    resources :contacts 

    offline = Rack::Offline.configure do 
    cache ["contacts/new", "contacts"] 
    public_path = Rails.root.join("public") 
    Dir[public_path.join("*.html"), 
     public_path.join("*/*.*")].each do |file| 
     p = Pathname.new(file) 
     cache p.relative_path_from(public_path) 
    end 

    network "/" 
    end 

    match '/application.manifest' => offline 
end 

的路由上面的文件將產生如下application.manifest

CACHE MANIFEST 
# 700ae3e3002382cb98b93c299d7b7bda151183b4703ef65d4c46b0ecf9c46093 
contacts/new 
contacts 
404.html 
422.html 
500.html 
index.html 
images/rails.png 
javascripts/application.js 
javascripts/jquery.js 
javascripts/jquery.min.js 
javascripts/rails.js 
stylesheets/scaffold.css 

NETWORK: 
/