Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

example on github page don't work #7

Open
angelomichel opened this Issue · 4 comments

4 participants

@angelomichel

Hi there,

I found out that the example that was posted does not work (at least nog in 1.8.6 @ rails3).

I am reffering to this bit:

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

This gives two errors:
#1 .join does not work on a string.
#2 .relative_path_name is a method not known to string either

Here is a fixed version:

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

  public_path = Rails.public_path
  Dir[public_path + "javascripts/*.js")].each do |file|
    cache file.gsub(public_path, "") #anyone know a better one? Without gsub?
  end

  network "/"
end
@arsduo

Hi Angelo,

Try this:

offline = Rails::Offline.configure do
  public_path = Pathname.new(Rails.public_path)
  Dir["#{public_path.to_s}/**/*"].each do |file|
    cache Pathname.new(file).relative_path_from(public_path) if File.file?(file)
  end
end

Using Pathname.new gives Rack::Offline the expected type of object.

Note that this is using Rails::Offline, a subclass of Rack::Offline that's provided with the Rack::Offline gem (this is where I found the solution). The Rails version sets the root to the Rails app's public root, among other things.

Best,

Alex

@mareczek

Where should i put this configuration? I tried to put it into config/initializers/rack_offline.rb with the following but it doesn't work:

offline = Rails::Offline.configure do

  cache "Georgia.ttf"

  public_path = Pathname.new(Rails.public_path)
  Dir[
      #"javascripts/*.js",
      #"stylesheets/*.css",
      #"images/*.*",
      #"static/*.*",
      File.join(public_path, "static/images/*.*")
    ].each do |file|
    file = Pathname.new(file)
    cache file.relative_path_from(public_path)
  end

  network "/"
end

Thank you :-)

@jlapier

@mareczek - I ended up putting it directly into my routes file:

offline = Rails::Offline.configure do
  # whatever
end

match "/application.manifest" => offline
@mareczek

I have an issue, but i don't know if it's just with the manifest or with roadie. When i specify network: "/" my browser (chrome) in production caches also pages. I don't want it to cache pages :(

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.