javascript - window.replace method not working in js when I try to insert a URL via rails -


i have piece of javascript force browser redirect:

window.location.replace("http://google.com") 

this works fine - however, when try , populate url via model in rails using;

window.location.replace("<%= @link.url %>") 

it fails because adds url onto end of link path myapp.com/links/google.com. not sure why isn't replacing entire url when type in manually. ideas?

notes: have link model url attribute , on show page. further down page outside of javascript @link.url shows link fine.

you need add protocol:

window.location.replace("http://"+"<%= @link.url %>"); 

Comments