user1919937
user1919937

Reputation: 447

Add HTML in a Link_to - Rails

Can I add HTML in a link_to?

For example, instead of <%= link_to post.title, post %> I'd prefer:

<%= link_to '<span>post.title</span>', post %>

Upvotes: 0

Views: 733

Answers (2)

alek
alek

Reputation: 331

I would use block as well but general approach is:

= link_to '', :href => some_path, :class=> 'some classes', :etc => 'some value' do
  %span your HTML here

The same in erb of course.

Upvotes: 0

Tolik Kukul
Tolik Kukul

Reputation: 2016

Use block:

<%= link_to(post) do %>
  <span>Test</span>
<% end %>

Upvotes: 2

Related Questions