0

有人可以给我一个快速解决方案吗?我已经做到了这一点: 我的路线:rack :: offline in rails 4.1问题

offline = Rack::Offline.configure do 
    cache ActionController::Base.helpers.asset_path("application.css") 
    cache ActionController::Base.helpers.asset_path("application.js") 
    cache ActionController::Base.helpers.asset_path("jquery.min.css") 
    cache ActionController::Base.helpers.asset_path("jquery.tmpl.min.css") 
    cache ActionController::Base.helpers.asset_path("style.js") 
    # cache ActionController::Base.helpers.asset_path("custom.css") 

    network "/" 
    end 
    get "/application.manifest" => offline 

在application.html.erb:

<html manifest="/application.manifest"> 

在我的Gemfile:

# gem 'rack-offline' 
# gem 'rack-offline', :github => 'pascalw/rack-offline' 
gem 'rack-offline', :git => 'https://github.com/wycats/rack-offline.git' 

Rails version: 4.1.6Ruby version: 2.1.3

http://localhost:3000/application.manifest的输出是:

CACHE MANIFEST 
# a5a8232b037b9e6234e3db79ab4b2bff8fffecd76c4124f456273146f70631b0 
/assets/application.css 
/assets/application.js 

NETWORK: 
/

我也曾在application.rb中加入ENV["RAILS_ASSET_ID"] = ""rails cast #247 Offline Apps Part 1。 请别人提醒我做错了什么?

+0

我想,你需要添加这routes.rb中 缓存的ActionController :: Base.helpers.asset_path(” jquery.js“) – amtest 2014-10-08 06:38:39

+0

ooh,lemie尝试一下 – ben 2014-10-08 06:53:03

+0

@amtest,我和你一样。但仍然无法正常工作。 CACHE MANIFEST #0751bc091a13f29326097384145d236d9a36b7cd41c91cd9358e5f539b452b13 /assets/jquery.js /assets/application.css /assets/application.js /assets/jquery.min.js /assets/jquery.tmpl.min.js /资产/ style.css /assets/custom.css NETWORK: / – ben 2014-10-08 07:31:21

回答

1

的routes.rb

offline = Rack::Offline.configure do 
#cache "images/masthead.png" 

cache ActionController::Base.helpers.asset_path("jquery.js") 
cache ActionController::Base.helpers.asset_path("jquery_ujs.js") 
cache ActionController::Base.helpers.asset_path("application.css") 
cache ActionController::Base.helpers.asset_path("application.js") 
cacheActionController::Base.helpers.asset_path("jquery.offline.js") 
cache ActionController::Base.helpers.asset_path("jquery.tmpl.min.js") 
cache ActionController::Base.helpers.asset_path("json.js") 
cache ActionController::Base.helpers.asset_path("offline_mode.js") 



network "/" 
end 
get "/application.manifest" => offline 

applicaiton.js像这样

//= require jquery 
//= require jquery_ujs 
//= require jquery.tmpl.min 
//= require jquery.offline 
//= require json 
//= require offline_mode 
//= require_tree . 
+0

我认为这应该很简单,但它很难解决它。只需缓存JS和CSS是唯一的问题。我已经完成了与您完全相同的操作。但我不确定是否应该添加if Rails.env.production?检查我的路线。当服务器运行时,application.manifest页面缓存清单 #.. /assets/application.js /assets/jquery.js /assets/jquery_ujs.js /assets/jquery.tmpl.min.js /assets/jquery.offline.js /assets/json.js /assets/custom.js /assets/validate.js /assets/application.css /assets/style.css /assets/custom.css NETWORK: / – ben 2014-10-09 11:03:47

+0

我是否提到过我正在关注ryan bates rail#247 Offline Apps Part 1 tutorial。这吸人,特别是如果我不想放弃。 – ben 2014-10-09 11:05:56

+0

用firebug在firefox中运行,并用萤火虫控制台检查它,这是我解决 – amtest 2014-10-09 11:16:52