1

如何使 rake-offline 在 rails 3.2.11 中工作?

我添加了初始化程序

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

我在路线中添加

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

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

并在 html 标签中添加清单。

它抛出错误

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

1 回答 1

1

在 Rails 3.2.11 中,Rails.public_path返回 a String,而不是Pathname对象。(看起来 Rails master 让它返回一个Pathname对象,这就是为什么 rack-offline 的文档可能会说以这种方式使用它)。

试试这个:

  public_path = Pathname.new(Rails.public_path)

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

于 2013-01-25T05:37:00.153 回答