Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-3.1ruby-on-rails-plugins

construct link_to in Rails 3.2.1


Here my designer change the way to use anchor tag in html template, so I need to change in my rails template too,

if he placed below tag in approved html pages,

<a href="#">About Me</a>

I am converting it like this way

<%= link_to "About Me", '#' %>

Now if he placed <a href="#">About <span> Me</a> with span tag in title

 <ul>
       <li><a href="#">About <span>Me</span></a></li>
 </ul>

Here is the output, basically span tag break the line and display in second line

About
Me

Now I need help to convert this tag with rails 3.2.1 tag.

like <%= link_to "About <span> Me</span>", '#' %>

How can I do that? (I know that will generate error message)


Solution

  • You need to make sure rails doesn't escape the html tags. You can do this either using html_safe or raw:

    <%= link_to "About <span> Me</span>".html_safe, '#' %>
    

    or

    <%= link_to raw("About <span> Me</span>"), "#" %>