如何在rails 3.2.11中进行rake-offline工作?
我添加了初始化程序
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)
答案 0 :(得分:1)
在Rails 3.2.11中,Rails.public_path
返回String
,而不是Pathname
对象。 (看起来Rails master让它返回一个Pathname
对象,这就是机架离线的文档可能会说以这种方式使用它的原因。)
请改为尝试:
public_path = Pathname.new(Rails.public_path)