Explanation: The creator of the message must be able to decide when the truncation will occur.
My blog has a Wordpress feature, such as [--- MORE ---], with the following helper function:
def more_split(content)
split = content.split("[---MORE---]")
split.first
end
def remove_more_tag(content)
content.sub("[---MORE---]", '')
end
In the index view, the message body will display everything before (but without) the [--- MORE ---] tag.
<%= raw more_split(post.rendered_body) %>
And in the show view everything will be displayed, starting with the body of the message, except for the tag [--- MORE ---].
<%=raw remove_more_tag(@post.rendered_body) %>
This solution currently works for me without a problem. Since I'm still new to programming, I am constantly wondering if there is a more elegant way to accomplish this .
How do you do this?
Thank you for your time.
This is an updated version:
<%=raw truncate(post.rendered_body,
:length => 0,
:separator => '[---MORE---]',
:omission => link_to( "Continued...",post)) %>
... and in view view:
<%=raw (@post.rendered_body).gsub("[---MORE---]", '') %>