Skip to content

Instantly share code, notes, and snippets.

@mbriggs
Created January 17, 2016 00:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbriggs/c489204a251e3914b384 to your computer and use it in GitHub Desktop.
Save mbriggs/c489204a251e3914b384 to your computer and use it in GitHub Desktop.
my rails helper for webpack dev server, and compiled into public
def include_js(file)
@_js_includes ||= {}
@_js_includes[file] ||= begin
manifest_path = Rails.root.join('public', 'assets', 'manifest.json')
if File.exist?(manifest_path)
manifest = JSON.parse(File.read(manifest_path))
path = "/assets/#{manifest[file]}"
else
path = "http://127.0.0.1:8080/#{file}"
end
%(<script type="text/javascript" src="#{path}"></script>).html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment