0

can someone give me a quick solution please? I have done this: My routes:

  offline = Rack::Offline.configure  do
    cache ActionController::Base.helpers.asset_path("application.css")
    cache ActionController::Base.helpers.asset_path("application.js")
    cache ActionController::Base.helpers.asset_path("jquery.min.css")
    cache ActionController::Base.helpers.asset_path("jquery.tmpl.min.css")
    cache ActionController::Base.helpers.asset_path("style.js")
    # cache ActionController::Base.helpers.asset_path("custom.css")

    network "/"
  end
  get "/application.manifest" => offline

in application.html.erb:

<html manifest="/application.manifest">

in my gemfile:

# gem 'rack-offline'
# gem 'rack-offline', :github => 'pascalw/rack-offline'
gem 'rack-offline', :git => 'https://github.com/wycats/rack-offline.git'

my Rails version: 4.1.6, Ruby version: 2.1.3

this is the output at http://localhost:3000/application.manifest is:

CACHE MANIFEST
# a5a8232b037b9e6234e3db79ab4b2bff8fffecd76c4124f456273146f70631b0
/assets/application.css
/assets/application.js

NETWORK:
/

I have also added ENV["RAILS_ASSET_ID"] = "" in application.rb as rails cast #247 Offline Apps Part 1. Please someone advise what I am doing wrong??

ben
  • 6,000
  • 5
  • 35
  • 42
  • i think, you need to add this to routes.rb cache ActionController::Base.helpers.asset_path("jquery.js") – amtest Oct 08 '14 at 06:38
  • @amtest, I have done it the same way as you. BUT still it is not working. CACHE MANIFEST # 0751bc091a13f29326097384145d236d9a36b7cd41c91cd9358e5f539b452b13 /assets/jquery.js /assets/application.css /assets/application.js /assets/jquery.min.js /assets/jquery.tmpl.min.js /assets/style.css /assets/custom.css NETWORK: / – ben Oct 08 '14 at 07:31
  • in which js, you put the code for offline process? – amtest Oct 08 '14 at 08:09
  • also i didn't find these files in you routes.rb cache ActionController::Base.helpers.asset_path("jquery.offline.js") cache ActionController::Base.helpers.asset_path("jquery.tmpl.min.js") cache ActionController::Base.helpers.asset_path("json.js") – amtest Oct 08 '14 at 08:11
  • It failed to work, could you share your routes file? Which rails and ruby versions were you using? – ben Oct 08 '14 at 22:25

1 Answers1

1

routes.rb

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

cache ActionController::Base.helpers.asset_path("jquery.js")
cache ActionController::Base.helpers.asset_path("jquery_ujs.js")
cache ActionController::Base.helpers.asset_path("application.css")
cache ActionController::Base.helpers.asset_path("application.js")
cacheActionController::Base.helpers.asset_path("jquery.offline.js")
cache ActionController::Base.helpers.asset_path("jquery.tmpl.min.js")
cache ActionController::Base.helpers.asset_path("json.js")
cache ActionController::Base.helpers.asset_path("offline_mode.js")



network "/"
end
get "/application.manifest" => offline

applicaiton.js something like this

//= require jquery
//= require jquery_ujs
//= require jquery.tmpl.min
//= require jquery.offline
//= require json
//= require offline_mode
//= require_tree .
amtest
  • 690
  • 1
  • 6
  • 26
  • I believe this should be very simple, but it's weird it is giving a hard time solving it. Just caching the JS and CSS is the only problem.I have done it exactly the same way as you. but i'm not sure is if I should add the if Rails.env.production? check in my routes. when the server is running, the application.manifest page CACHE MANIFEST # .. /assets/application.js /assets/jquery.js /assets/jquery_ujs.js /assets/jquery.tmpl.min.js /assets/jquery.offline.js /assets/json.js /assets/custom.js /assets/validate.js /assets/application.css /assets/style.css /assets/custom.css NETWORK: / – ben Oct 09 '14 at 11:03
  • And did I mention I was following ryan bates rails cast #247 Offline Apps Part 1 tutorial. This sucks man, especially if I don't wanna give up. – ben Oct 09 '14 at 11:05
  • run in firefox with firebug, and check it with firebug console, this is the way i have solved – amtest Oct 09 '14 at 11:16
  • sure. as I try it you check this question i have posted a detailed explanation. http://stackoverflow.com/questions/26277434/rails-4-1-6-using-rack-offline-gem-to-make-offline-app-manifest-caching-and-lo – ben Oct 09 '14 at 11:38
  • can you paste here the development.rb also the application.html.erb – amtest Oct 09 '14 at 11:43
  • done. I have updated my questions.Also here http://stackoverflow.com/questions/26277434/rails-4-1-6-using-rack-offline-gem-to-make-offline-app-manifest-caching-and-lo – ben Oct 10 '14 at 09:44
  • Use this question, it is more detailed. I have updated it and included the files. http://stackoverflow.com/questions/26277434/rails-4-1-6-using-rack-offline-gem-to-make-offline-app-manifest-caching-and-lo. – ben Oct 10 '14 at 11:06