No commit activity in last 3 years
No release in over 3 years
TinyMCE plugin for file uploads in Rails >= 4.0. Document storage is handled manually, so works with everything.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 4.0

Runtime

< 5, >= 4.0
 Project Readme

tinymce-rails-fileupload plugin

Simple plugin for TinyMCE4 that allows for uploading files from your computer and inserting a link to the uploaded document.

It makes no assumption on how you store the files, it simply POSTs data to a URL and expects a JSON response (see the Setup).

This plugin started as a copy of tinymce-rails-imageupload.

Demo

A small app demonstrating a working setup with Rails 4 is available here.

Requirements

  • Rails >= 4.0
  • TinyMCE4 using the advanced theme

Installation

Add this line to your application's Gemfile:

gem 'tinymce-rails-fileupload'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install tinymce-rails-fileupload

Gem Version

Setup

Set up TinyMCE as you would normally, but in the call to .tinymce(), add

plugins: "uploadfile"
# toolbar option must include "uploadfile" somewhere to have the button appear

and the rest should happen automatically.

Set up upload URL and handler

The plugin defaults to POSTing to /tinymce_assets.

You may modify it by supplying the option uploadfile_form_url in the call to .tinymce()

Routing to your controller must be done manually. Set it up using something similar in routes.rb:

post '/tinymce_assets' => 'tinymce_assets#create'

This action gets called with a file parameter creatively called document[file], and must respond with JSON, containing the URL and title of the document.

The JSON has to be returned with a content type of "text/html" to work.

Example:

class TinymceAssetsController < ApplicationController
  def create
    document = Document.create(document_params)

    render json: {
      document: {
        url: document.file.url,
        title: document.title
      }
    }, layout: false, content_type: "text/html"
  end
  
  private
  
    def document_params
      params.require(:document).permit(:file, :title)
    end
end

Inserted HTML is just <a href="..." title="...">Link text</a>.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/tinymce-rails-fileupload/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request