My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit and update your bookmarks.

Wednesday, 22 December 2010

Rails3 'link_to' displays literal HTML on front end

In the last month, I have been working on a rails3 app and I ran across this interesting problem where I need to create a href link to a another page from my current page.

In my view i have written

<%= "Please click on this link #{link_to('here', new_house_path)}" %>

And interestingly this is displayed as

Please click on this link <a href="http://localhost:3000/houses/new">here</a>

on the front end.

Hours of frustration and google searches leads me to doing this:

<%= ("Please click on this link #{link_to('here', new_house_path)}").html_safe %>;

which then is displayed correctly on front end

Please click on this link here

if that isnt clear enough, the trick is you need to wrap the string with a 'html_safe' method

Off i go to learn more stuff .....