Saturday, 14 September 2013

Rails View - How to escape special characters to include within a link

Rails View - How to escape special characters to include within a link

I am trying to escape special characters e.g. (space : / &) for inclusion
into a link. I have tried the following but it will only escape '#'
characters.
<a href="https://twitter.com/share?text=<%=location.title.html_safe%><%=h
root_url(:anchor =>
"_lat=#{location.latitude}&long=#{location.longitude}&zoom=17").html_safe%>">Tweet</a>
I have also tried <%=CGI.escapeHTML location.title%><%=CGI.escapeHTML
root_url(...)%> it does not escape spaces or the http:// in root_url
Thanks.

No comments:

Post a Comment