ROR + Access Cookie Value Assigned by RubyCode in Javascript Function
Is there any way to access Cookie value assigned in RUBY Code at Javascript Function.
Code in Ruby
cookies开发者_如何学Python[:url] = { :value => request.url }
Javascript Code:
var cookieURL = document.cookie;
But I want simple URL like
http://localhost:3000/profile?id=12
I am getting some decoded URL. Now I wanna access the cookie value in Javascript code. Please suggest something. ??
Try this in your javascript.
var cookieURL = document.cookie;
// - - > "url=http%3A%2F%2Flocalhost%3A3000%2Fhome"
//removes the "url=" portion
cookieURL = cookieURL.slice(4);
//decodes the URI
var decoded = decodeURIComponent(cookieURL);
alert(decoded); // - - > http://localhost:3000/home
This code is working here: http://jsbin.com/ubudo4
精彩评论