简体   繁体   English

如何在Rails 3.2应用程序中设置机架离线

[英]How to set up rack-offline in rails 3.2 app

How to make rake-offline work in rails 3.2.11 ? 如何在Rails 3.2.11中使脱机工作?

I added initializer 我添加了初始化器

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

  public_path = Rails.public_path
  Dir[public_path.join("javascripts/*.js")].each do |file|
    cache file.relative_path_from(public_path)
  end

  network "/"
end

I added in routes 我在路线中添加了

match "/application.manifest" => Rails::Offline

  Rack::Offline.configure do
    cache "assets/application.js"
    cache "assets/application.css"   
    network "/"
  end

and added manifest in html tag. 并在html标签中添加清单。

It throws error 引发错误

/initializers/offline.rb:5:in `block in <top (required)>': undefined method `join' for "/Sites/Ruby/project/public":String (NoMethodError)

In Rails 3.2.11, Rails.public_path returns a String , not a Pathname object. 在Rails 3.2.11中, Rails.public_path返回String ,而不是Pathname对象。 (It looks like Rails master has it returning a Pathname object which is why rack-offline's documentation might say to use it that way). (看起来Rails master会返回一个Pathname对象,这就是为什么机架脱机文档可能会说要使用它的原因)。

Try this instead: 尝试以下方法:

  public_path = Pathname.new(Rails.public_path)

See https://github.com/wycats/rack-offline/issues/7 参见https://github.com/wycats/rack-offline/issues/7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 强制离线(或Rails)更新缓存清单 - Force rack-offline (or Rails) to update caching manifest 如何在另一个Rails应用程序中将Rails应用程序设置为机架应用程序? - How do I set up rails apps as rack apps within another rails app? 如何在开发模式下强制Rails 3.2按请求重新加载已安装的机架应用程序? - How can I force Rails 3.2 to reload mounted rack app per request in development mode? 如何解决rails中的机架应用程序错误? - How to solve rack app error in rails? Rails - rack :: offline不会永久缓存供应商的javascript - Rails - rack::offline not permanently caching vendor javascript Rails机架保护的用法,错误“您需要*在* Rack :: Protection :: SessionHijacking之前设置会话中间件” - rails rack-protection usage, error “you need to set up a session middleware *before* Rack::Protection::SessionHijacking” 如何将独立的Rack应用程序安装到Ruby On Rails应用程序中? - How do I mount a standalone Rack app into a Ruby On Rails app? 如何设置与Rails 3.2中的RSpec和黄瓜同时使用的Factory Girl相关配置 - How to set up Factory Girl related configuration to be used by both RSpec and cucumber in Rails 3.2 如何在rails app中设置Twitter gem? - How to set up the Twitter gem in rails app? 如何调试由工头启动的rails(3.2)应用程序? - How to debug a rails (3.2) app started by foreman?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM