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 9068495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:12:26+00:00 2026-06-16T17:12:26+00:00

I added a document column to my Post model, so now I’m able to

  • 0

I added a document column to my Post model, so now I’m able to add txt files to it:

post.rb:

has_attached_file :document
validates_attachment_content_type :document, :content_type => 'text/plain'

console:

 #<Post id: 92, content: "document upload test", user_id: 1, created_at: "2013-01-02 10:23:13", updated_at: "2013-01-02 10:23:13",
 title: "document upload test", document_file_name: "test.txt",
 document_content_type: "text/plain", document_file_size: 15,
 document_updated_at: "2013-01-02 10:23:13">

So now, I would like to turn the content inside test.txt into raw text. So I can do something like this in my controller:

@post.content = [TEXT INSIDE test.txt]

Any suggestions?

  • 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-16T17:12:27+00:00Added an answer on June 16, 2026 at 5:12 pm

    Using a before_save callback, then find the path, open the file and call File::read on the opened file.

    class Post
      before_save :contents_of_file_into_body
    
      private
      def contents_of_file_into_body
        path = document.queued_for_write[:original].path
        content = File.open(path).read
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one excel document with two columns. i only add text in one
I added a workflow to my document library (with a custom content type) and
I've added an header and a footer on my document by PdfPageEventHelper. The document
I've created an index with various bits of data for each document I've added,
I added a hoverboard on my site that flips over to reveal more text.
Is there any way I can add a column based on another column's attribute?
So, I have a model with three entities: Document , Template and Origin .
The goal is to add a column of paragraph numbers to a RichTextBox (the
A database table is used to store editing changes to a text document. The
I cannot get the Full-Text search to work on PDF files I am loading

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.