Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3962460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:05:58+00:00 2026-05-20T03:05:58+00:00

Clarification: The creator of the post should be able to decide when the truncation

  • 0

Clarification: The creator of the post should be able to decide when the truncation should happen.

I implemented a WordPress like [—MORE—] functionality in my blog with following helper function:

# application_helper.rb

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 post body will display everything up to (but without) the [—MORE—] tag.

# index.html.erb
<%= raw more_split(post.rendered_body) %>

And in the show view everything from the post body will be displayed except the [—MORE—] tag.

# show.html.erb
<%=raw remove_more_tag(@post.rendered_body) %>

This solution currently works for me without any problems.
Since I am still a beginner in programming I am constantly wondering if there is a more elegant way to accomplish this.

How would you do this?

Thanks for your time.


This is the updated version:

# index.html.erb
<%=raw truncate(post.rendered_body,  
                :length => 0, 
                :separator => '[---MORE---]', 
                :omission => link_to( "Continued...",post)) %>

…and in the show view:

# show.html.erb
<%=raw (@post.rendered_body).gsub("[---MORE---]", '') %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:05:58+00:00Added an answer on May 20, 2026 at 3:05 am

    I would use just simply truncate, it has all of the options you need.

    truncate("And they found that many people were sleeping better.", :length => 25, :omission => '... (continued)')
    # => "And they f... (continued)"
    

    Update

    After sawing the comments, and digging a bit the documentation it seems that the :separator does the work.

    From the doc:

    Pass a :separator to truncate text at a natural break.
    

    For referenece see the docs

    truncate(post.rendered_body, :separator => '[---MORE---]')
    

    On the show page you have to use gsub

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For clarification, are you able to use MySQL this way to sort? ORDER BY
(If anything here needs clarification/ more detail please let me know.) I have an
Edit: Just for clarification I am using python, and would like to do this
I'd like clarification on the C++ standard, specifically where it says (my interpretation) in
For clarification : I want all the custom dialogs to look like system default
Clarification: Put simply, I'd like to put an ASP.NET UpdatePanel inside the info window
I looking for a clarification regarding the pointers. I have compiled the following code
I would like some clarification on what the code in front of the HTML
A Clarification, if I have a table that has the following fields.... ProductCategoryID, CategoryName,
I'm looking for clarification on the following 2 points with regards to DDD. 1.Can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.