如何离线更改机架的默认行为 [英] how to change default behaviour of rack offline

查看:36
本文介绍了如何离线更改机架的默认行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在里亚尔中离线使用机架,以使我的网页可离线使用.默认情况下,rack offline 会将 public 文件夹中的所有文件放入缓存清单.我应该在哪个文件中进行更改,以便将我想要的文件添加到缓存清单中.我想将该文件包含在我的视图文件夹中.

I am trying to use rack offline in rials to make my webpage available offline. By default rack offline takes all files from the public folder into the cache manifest. In which file should I make changes so that it will take the add the file that I want into the cache manifest. I want to include the file in my views folder.

推荐答案

您需要将其添加到 routes.rb 文件中.这是我的带有自定义清单的 routes.rb 文件.这将为您提供索引和新路由以及公共根目录 (*.html) 中的所有 html 文件和公共子文件夹中的每个文件 (*/*.*).您可以根据需要对公共文件夹中的内容进行切片和切块.

You need to add it to your routes.rb file. Here is my routes.rb file with a customized manifest. This will give you the index and the new routes as well as all of the html files in your public root (*.html) and every file in a sub-folder to public (*/*.*). You can slice and dice that however you need it for stuff in the public folder.

我不知道如何在离线时获取数据库特定的路由,例如显示和编辑.我想需要 Javascript.查看 Railscast 第 248 集,了解集成 JS 的一些想法

I don't know how to get the database specific routes like show and edit while offline. I would imagine Javascript is needed. Check out Railscast episode 248 for some ideas for integrating 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

The routes file above will produce the following 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:
/

这篇关于如何离线更改机架的默认行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆