Last active
August 29, 2015 13:56
-
-
Save sbrauer/9237521 to your computer and use it in GitHub Desktop.
DNI Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add to ag/app/routes/routes.rb | |
get '/dni_demo/' do | |
zid = request.cookies['zid'] | |
msg = zid ? "Your zid is #{zid}" : "You have no zid" | |
content_type 'text/javascript' | |
%{document.getElementsByTagName('span')[0].textContent = "#{msg}";} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To demo, add a script tag similar to the following just before closing body tag of http://primedia.railsplayground.net/dynamic-phone/:
Expected result:
Hello There
My phone number is Your zid is Nrk9zSwUwZS51b2elOoWwvHORQf.
Try to change it dynamically. I dare you.
Notes: This is a very quick and dirty jsonp-like approach. Since the cookie reading is done server-side, we'd have to be careful to avoid varnish caching issues. If varnish respects cache-control headers (I don't know) we could set No-Cache in the response.
Otherwise we might have to add the script tag dynamically and add a cache-busting query param.