Skip to content

Instantly share code, notes, and snippets.

@carlosipe
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save carlosipe/dc163297f527f77e91bb to your computer and use it in GitHub Desktop.

Select an option

Save carlosipe/dc163297f527f77e91bb to your computer and use it in GitHub Desktop.
module Helpers
def javascript_tag(pathname)
"<script src='#{asset_url(pathname)}'></script>"
end
def stylesheet_tag(pathname)
"<link href='#{asset_url(pathname)}' rel='stylesheet'>"
end
private
def asset_url(pathname)
dir = File.dirname(pathname)
ext = File.extname(pathname)
basename = File.basename(pathname, ext)
time = File.mtime(File.join(PUBLIC_PATH, pathname)).to_i.to_s
File.join(dir, "#{basename}__#{time}#{ext}")
end
end
rewrite (.*)__([0-9]+)(\.js) $1$3 break;
rewrite (.*)__([0-9]+)(\.css) $1$3 break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment