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

时间:2013-01-25 05:06:05

标签: ruby-on-rails ruby-on-rails-3 offline

如何在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)

1 个答案:

答案 0 :(得分:1)

在Rails 3.2.11中,Rails.public_path返回String,而不是Pathname对象。 (看起来Rails master让它返回一个Pathname对象,这就是机架离线的文档可能会说以这种方式使用它的原因。)

请改为尝试:

  public_path = Pathname.new(Rails.public_path)

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