title: Grabbing the text from .doc, .docx, and rtf files and displaying them into a text field (Rails)
body: <p>I have a <code>Post</code> model:</p>
  
  <pre><code>  create_table "posts", :force =&gt; true do |t|
      t.string   "title"
      t.string   "content"
      t.integer  "user_id"
      t.datetime "created_at",                            :null =&gt; false
      t.datetime "updated_at",                            :null =&gt; false
      t.integer  "comments_count",     :default =&gt; 0,     :null =&gt; false
      t.boolean  "published",          :default =&gt; false
      t.datetime "published_at"
      t.boolean  "draft",              :default =&gt; false
    end
  </code></pre>
  
  <p>And this is its form:</p>
  
  <pre><code>&lt;%= form_for(@post, :html =&gt; { :multipart =&gt; true }) do |f| %&gt;
    &lt;%= render 'shared/error_messages' %&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :title %&gt;
      &lt;%= f.text_field :title %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :content %&gt;
      &lt;%= f.text_area :content %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :draft %&gt;
      &lt;%= f.check_box :draft %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I'm looking for a way to grab the text from <code>.doc, .docx, and rtf</code> files and displaying them into the <code>content</code> text field (so the user doesn't have to open his file, copy, and paste the text into the form).</p>
  
  <p>Any suggestions?</p>
  
  <p>(Is there any gem, text editor, or jQuery plugin that accomplishes this?)?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Got stuck here:</p>
  
  <p><strong>post.rb:</strong></p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    require 'docx'
    .
    .
    .  
    def read_docx
      d = Docx::Document.open(self.document)
      d.each_paragraph do |p|
        puts d
      end
    end
  end
  </code></pre>
  
  <p><strong>posts_controller.rb:</strong></p>
  
  <pre><code>class PostsController &lt; ApplicationController
    before_filter :authenticate_user!, :except =&gt; [: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
    .
    .
    .
  </code></pre>
  
  <p><strong>posts/new.html.erb:</strong></p>
  
  <pre><code>&lt;%= form_for(@post, :html =&gt; { :multipart =&gt; true }) do |f| %&gt;
    &lt;%= render 'shared/error_messages' %&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :title %&gt;
      &lt;%= f.text_field :title %&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;
      &lt;%= f.label :content %&gt;
      &lt;%= f.text_area :content, :value =&gt; @doc_text %&gt;
    &lt;/div&gt;
    .
    .
    .
  </code></pre>
  
  <p><strong>I already made Paperclip upload docx files</strong></p>
  
  <p>I created a new field called <code>:document</code></p>