Skip to content

Instantly share code, notes, and snippets.

@BenMorganIO
Created September 27, 2014 07:14
Show Gist options
  • Select an option

  • Save BenMorganIO/0c55638993b08bc74383 to your computer and use it in GitHub Desktop.

Select an option

Save BenMorganIO/0c55638993b08bc74383 to your computer and use it in GitHub Desktop.
Dart2JS Rails Caching Issue
# For some reason you have to delete the cache beforehand
# when you use the dart2js gem with Rails.
# Just add this before_action in your controller and you're
# good
class ApplicationController < ActionController::Base
before_action :remove_old_dart_files
protect_from_forgery with: :exception
private
def remove_old_dart_files
files = Dir["#{Rails.root}/tmp/cache/assets/dart2js*"]
dart_app_mtime = File.mtime("#{Rails.root}/app/assets/dart/dart_app.dart")
files.each do |file|
File.delete(file) if File.mtime(file) < dart_app_mtime
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment