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

  • Home
  • SEARCH
  • 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 8708849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:13:55+00:00 2026-06-13T04:13:55+00:00

We store our blog posts in a text column in our database. We need

  • 0

We store our blog posts in a text column in our database. We need a “preview” of the blog post for our blog’s home page. That way, we can display the last couple days’ blog posts with links to read the whole thing.

Is there a way in rails to pull out a certain amount of a text column? Maybe the first x bytes? I understand this won’t be the same length for every blog post, but it should get it in the general area.

Or maybe do some html/css hack where we overflow a div and add an elipse to the div?

I could also see creating a separate “preview” column, but that feels very hacky.

Rails 3.2.1. Database is MySQL

  • 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-06-13T04:13:56+00:00Added an answer on June 13, 2026 at 4:13 am

    If I undertood correctly, you want something that transforms a long text entry into a limited preview text, like This is a preview text, and it says that....

    To do that, you can simple do something like:

    text = post.text[0..100] + "..."
    

    It basically gets the first 100 characters from the text.
    If you want something more complex, that takes words in account (so you don’t end up with things like This is a previ..., you can have a function that separates the text into words and add them to the final text until they reach the required length, like:

    text = post.text
    words = text.split(" ")
    final_text = ""
    words.each do |word|
        final_text += word if final_text.size + word.size < DESIRED_LENGTH
    end
    final_text += "..."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have rtf text stored in our database that looks like the following: {\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0
I have 100000 Ids to store into our DataBase. Id is in string format.each
In one page of our site, I have this code: $_SESSION['returnURL'] = /store/checkout/onepage; and
I have been investigating the best way to store our solutions in SVN and
We have our own blog system and the post data is stores a raw
We store all our application and db passwords in plain text in source control.
Our Magento store uses the Website Payments Pro payment gateway through PayPal. For the
Our software has data to store, so it also install MYSQL, a root user
Our business currently has an online store and recently we've been offering free specials
i wanted to know where we should store the db in our project and

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.