Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example on github page don't work #7

Open
angelomichel opened this issue Jan 12, 2011 · 4 comments
Open

example on github page don't work #7

angelomichel opened this issue Jan 12, 2011 · 4 comments

Comments

@angelomichel
Copy link

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
Copy link
Contributor

arsduo commented Jun 1, 2011

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
Copy link

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
Copy link

jlapier commented Jun 2, 2012

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

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

match "/application.manifest" => offline

@mareczek
Copy link

mareczek commented Jun 4, 2012

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants