Jake
Jake

Reputation: 1380

How to use truncate with link_to in Rails?

I'm following along here: Text Helper

Specifically I'm using the last example and have in my code:

<%= truncate_html(posts.content) {link_to "Continue", post_path(posts.url_name)}%>

The first part of the truncate works but the link does not appear. Any idea why my link isn't appearing?

Upvotes: 0

Views: 273

Answers (2)

I don't know the truncate_html, but you could use this questions answer with a block in the end:

<%= truncate(posts.content, :escape => false) { link_to "Continue", post_path(posts.url_name) } %>

That would create the result you want.

Upvotes: 1

rantingsonrails
rantingsonrails

Reputation: 568

truncate_html does not appear to be a valid method in the Rails base code. Try with truncate

<%= truncate(posts.content) {link_to "Continue", post_path(posts.url_name)}%>

Upvotes: 0

Related Questions