Socket
Book a DemoInstallSign in
Socket

tinymce-rails-fileupload

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinymce-rails-fileupload

0.0.3
bundlerRubygems
Version published
Maintainers
1
Created
Source

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

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

FAQs

Package last updated on 25 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.