amye
amye

Reputation: 115

How can I add additional tags in a link in rails?

The following code:

<%= link_to content_tag(:span, 'foo'), :action => 'new' %>

Renders the link like this:

<a href="/new"><span>foo</span></a>

I would like to add the bold tags after the ending span tag like this:

<a href="/new"><span>foo</span><b></b></a>

How can I add the tags after the ending span tag?

Upvotes: 2

Views: 162

Answers (1)

Adam Lassek
Adam Lassek

Reputation: 35505

You can pass link_to a block instead of a string param:

<%= link_to :action => 'new' do %>
  <span>foo</span>
  <strong></strong>
<% end %>

Note: If you're on Rails 2.3 or earlier, use:

<% link_to :action => 'new' do %>

Upvotes: 6

Related Questions