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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:02:36+00:00 2026-06-13T03:02:36+00:00

I have a Post model: create_table posts, :force => true do |t| t.string title

  • 0

I have a Post model:

  create_table "posts", :force => true do |t|
    t.string   "title"
    t.string   "content"
    t.integer  "user_id"
    t.datetime "created_at",                            :null => false
    t.datetime "updated_at",                            :null => false
    t.integer  "comments_count",     :default => 0,     :null => false
    t.boolean  "published",          :default => false
    t.datetime "published_at"
    t.boolean  "draft",              :default => false
  end

And this is its form:

<%= form_for(@post, :html => { :multipart => true }) do |f| %>
  <%= render 'shared/error_messages' %>
  <div class="field">
    <%= f.label :title %>
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :content %>
    <%= f.text_area :content %>
  </div>

  <div class="field">
    <%= f.label :draft %>
    <%= f.check_box :draft %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

I’m looking for a way to grab the text from .doc, .docx, and rtf files and displaying them into the content text field (so the user doesn’t have to open his file, copy, and paste the text into the form).

Any suggestions?

(Is there any gem, text editor, or jQuery plugin that accomplishes this?)?

EDIT:

Got stuck here:

post.rb:

class Post < ActiveRecord::Base
  require 'docx'
  .
  .
  .  
  def read_docx
    d = Docx::Document.open(self.document)
    d.each_paragraph do |p|
      puts d
    end
  end
end

posts_controller.rb:

class PostsController < ApplicationController
  before_filter :authenticate_user!, :except => [:show, :index]
  .
  .
  .
  def create
    @user = current_user
    @post = @user.posts.new(params[:post])
    @doc_text = (no idea what to do here)

    if @post.save
      redirect_to @post, notice: 'post was successfully created.'
    else
      render action: "new"
    end
  end

  def edit
    @post = Post.find(params[:id])
  end
  .
  .
  .

posts/new.html.erb:

<%= form_for(@post, :html => { :multipart => true }) do |f| %>
  <%= render 'shared/error_messages' %>
  <div class="field">
    <%= f.label :title %>
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :content %>
    <%= f.text_area :content, :value => @doc_text %>
  </div>
  .
  .
  .

I already made Paperclip upload docx files

I created a new field called :document

  • 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-13T03:02:40+00:00Added an answer on June 13, 2026 at 3:02 am

    Well I just tried docx gem and it works fine. You can get 2 examples on its github page. Sadly it does not work for doc files.

    For them you can use this gem here. There is some example on the github page, but if you want to get the whole content of the doc file just do like this:

    require 'msworddoc-extractor'
    
    MSWordDoc::Extractor.load('sample.doc') do |doc|
      puts doc.whole_contents
    end
    

    There are other methods you can call for doc, like document or header. Again, check the github page.

    For rtf you can go with this gem as well.

    Now, to pass it inside the content is easy. Just definy how you will get the data from the files, like an external lib called on the controller:

    @doc_text = Parser.doc("file.doc")
    @docx_text = Parser.docx("file.docx")
    @rtf_text = Parser.rtf("file.rtf")
    

    Or just get the values directly or by any method you have in mind. To show it on view you just have to add :value option like this:

    <%= f.text_area :content, :value => @doc_text %> 
    #Where @doc_text is the data from file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Post model: create_table posts, :force => true do |t| t.string
Assuming i have a post model with created_at, title, and id. How can i
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I have a Topic model and a Post model. A Topic has many Posts,
Let's say I have User model and Post model. Post model contains field user_id
I have a typical, Post model: class Post< ActiveRecord::Base validates_presence_of :user_id #Line 1 validates_presence_of
I have 2 multi-table inherited models like these: class Post(models.Model): title = models.CharField(max_length=100, blank=True,
We're using Rails 3.2.3, Ruby 1.9.1, and HAML. We have a Post model and
I have a Category and a Post model, with each Post belonging to a
I have a User model, a Post model, and an Interest model. User has_many

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.