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