Reputation: 1357
I would like to insert HTML <BR>
tag within the link_to ERB tag as show below:
<%= link_to((@Name + "<BR>" + @Surname), my_action_path %>
What would be the correct way of doing this?
Upvotes: 0
Views: 605
Reputation: 11035
Since @Name
and @Surname
seem like they could be user-entered, you'll want to be careful here...
<% @name = "<script>alert('bad');</script>First Name"
@surname = "<script>alert('another bad');</script>Last Name" %>
<%= link_to(("".html_safe + @name + "<br />".html_safe + @surname), '#') %>
Trying with either of the other answers leaves you with 2 alert boxes (meaning you now have a XSS vulnerability)...this way outputs the script tags as text
Upvotes: 0
Reputation: 113
<%= link_to( raw(@Name+"<br>"+@Surname) , my_action_path ) %>
You can achieve this using 'raw' function provided by rails.
Upvotes: 2