John Davis
John Davis

Reputation: 172

Can't use raw after truncate rails

The trouble is if I use <% @description = (truncate(post.content, :separator => '[---MORE---]', :length => 0))%> and then I try to print it - <%= raw @description %> I still see all html tags.

Upvotes: 2

Views: 1120

Answers (1)

mechanicalfish
mechanicalfish

Reputation: 12826

truncate escapes the string by default, but you can turn it off using :escape option:

@description = (truncate(post.content, :separator => '[---MORE---]', :length => 0, :escape => false))

Other approach would be to mark the post.content as html safe:

truncate(post.content.html_safe, ...

If you do this you can even remove the raw.

Upvotes: 10

Related Questions