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&gt;

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 …..

This entry was posted in Software Testing and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s