Ruby on Rails Truncate text - can I use it for a combination of title and content?

Posted by Quhby on Stack Overflow See other posts from Stack Overflow or by Quhby
Published on 2010-04-28T22:39:17Z Indexed on 2010/04/28 23:57 UTC
Read the original article Hit count: 254

Filed under:
|

I have

<%=link_to topic.title, topic_path(topic) %>
- <%= truncate(topic.description_without_embed, :length=>50, :omission =>"...") %>

But what I really want to do is to truncate both the title and the post to 50 characters. How can this be done?

The output should look something like

Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Curabitur eu dolor est, id pharetra lectus. Phasellus nec feugiat dolor. Curabitur feugiat ultrices leo ut egestas. Nullam nec nisi in ligula feugiat placerat. Ut adipiscing urna consequat tortor euismod pretium. Maecenas eget quam aliquet orci blandit eleifend eu et quam. Donec.

instead of

Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu dolor est, id pharetra lectus. Phasellus nec feugiat dolor. Curabitur feugiat ultrices leo ut egestas. Nullam nec nisi in ligula feugiat placerat. Ut adipiscing urna consequat tortor euismod pretium. Maecenas eget quam aliquet orci blandit eleifend eu et quam. Donec.

I don't need to use the truncate method, any method would be helpful. Thanks.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about truncate