Coder Social home page Coder Social logo

tinymce-rails-imageupload's Introduction

IMPORTANT NOTE:

This repository is no longer maintained, as I do not use TinyMCE for anything any more. I also understand that TinyMCE 4 is quite old. Luckily, Frank Groeneveld has written a blog post detailing how to get image uploads working with TinyMCE 6 and Rails that I recommend checking out.

This version is being rewritten to work with TinyMCE 4.x, and is currently not very tested. Use at your own risk, feedback welcome. For the stable version targetting TinyMCE 3, see the tinymce3 branch

tinymce-rails-imageupload

Simple plugin for TinyMCE that allows uploading images and inserting. It makes no assumptions about how you store the images, it simply POSTs to a URL and expects JSON back (see the Setup section).

This plugin started as a copy of work done by Peter Shoukry, but has since mutated into something entirely different.

Support for TinyMCE 3 is currently available in the tinymce3 branch. The master branch is targetting TinyMCE 4.x.

Demo

A small demo app demonstrating a working setup for Rails 3.2 (demo, source), and for Rails 4 (demo, source) is available for study.

Requirements

  • Rails >= 3.1
  • TinyMCE4 using the advanced theme

Setup

Add the gem to your Gemfile

gem 'tinymce-rails-imageupload', '~> 4.0.0.beta'

# or use git

gem 'tinymce-rails-imageupload', github: 'PerfectlyNormal/tinymce-rails-imageupload'

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

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

and the rest should happen automatically.

You can also globally have imageupload globally disabled but enabled on specific instances.

# tinymce.yml
toolbar: bold italic underline | uploadimage
plugins:
  - uploadimage
uploadimage: false
<%= tinymce uploadimage: true %>

Set up upload URL and handler

The plugin defaults to POSTing to /tinymce_assets. You may modify it by supplying the option uploadimage_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 file, and must respond with JSON, containing the URL to the image.

The JSON has to be returned with a content type of "text/html" to work, which is hopefully going to be fixed (issue #7).

Example:

class TinymceAssetsController < ApplicationController
  def create
    # Take upload from params[:file] and store it somehow...
    # Optionally also accept params[:hint] and consume if needed

    render json: {
      image: {
        url: view_context.image_url(image)
      }
    }, content_type: "text/html"
  end
end

If the JSON response contains a width and/or height key, those will be used in the inserted HTML (<img src="..." width="..." height="...">), but if those are not present, the inserted HTML is just <img src="...">.

Hint param

Per request hint data can be sent to the create action through the call to .tinymce() or tinymce.yml. You may use this to relay any hints you wish (for example, blog post ID #) to the controller.

  • uploadimage_hint_key - override the hint key. Default is hint.
  • uploadimage_hint - hint value.

Example:

<%= tinymce uploadimage_hint_key: 'post_id', uploadimage_hint: @post.id %>

Would result in a params object that looks like this:

{
  "post_id": 1,
  "file": ...,
  // ...
}

Model attributes

Params can be sent in a more standard attributes format by setting uploadimage_model.

  • uploadimage_model - nest attributes within model namespace.

Example:

<%= tinymce uploadimage_model: 'post' %>

Would result in a params object that looks like this:

{
  "post": {
    "file": ...,
    // ...
  },
}

Default class for img tag

By default the plugin doesn't assign any class to the img tag. You can set the class(es) by supplying the uploadimage_default_img_class option in the call to .tinymce().

class="..." will only be added to the img tag if a default or custom class is specified. Otherwise the inserted HTML is just <img src="...">.

Custom classes

You can set image_class_list to an array of title, value objects to provide uploaders a pre-defined list of CSS classes to apply.

# tinymce.yml
image_class_list:
  - title: 'Center'
    value: 'img-center'
  - title: 'Left thumbnail'
    value: 'img-left img-thumbnail'
  - title: 'Right thumbnail'
    value: 'img-right img-thumbnail'

Asset Pipeline

Several people have had trouble with asset precompilation using the asset pipeline, both for the locales, and the plugin itself.

Depending on your version of Rails, and the alignment of the moon, it might work out of the box, or you'll have to add something like this in your configuration:

config.assets.precompile += %w( tinymce/plugins/uploadimage/plugin.js tinymce/plugins/uploadimage/langs/en.js )

Obviously adjust depending on the language or languages you want to use.

Since TinyMCE doesn't know about the asset pipeline however, you could just place it under public/, and that should probably work as well. As with all things Rails and assets related, YMMV.

Error handling

To notify the uploader that an error occurred, return JSON containing an error key with a message. The message gets show in a paragraph with the ID error_message, and the input label gets the class invalid.

Example response:

"{"error": {
  "message": "Invalid file type. Only .jpg, .png and .gif allowed"
}}"

Internationalization

I18n is taken care of by tinymce-rails. This gem includes strings for en, de, es, fr, nb, pt, pt_BR, ru and zh-cn. To add your own language, create the files <code>.js in app/assets/javascripts/tinymce/plugins/uploadimage/langs in your application, or fork the gem and add your own translations there.

The format and available strings are listed below:

nb.js

tinyMCE.addI18n('nb', {
  'Insert an image from your computer': 'Sett inn et bilde fra datamaskinen',
  'Insert image': "Sett inn bilde",
  'Choose an image': "Velg et bilde",
  'You must choose a file': "Du m\u00e5 velge en fil",
  'Got a bad response from the server': "Fikk et ugyldig svar fra serveren",
  "Didn't get a response from the server": "Fikk ikke svar fra serveren",
  'Insert': "Sett inn",
  'Cancel': "Avbryt",
  'Image description': "Alternativ tekst for bilde",
});

Versioning

The major, minor and patch version of this gem will be mirroring the release of tinymce-rails it is tested against.

Signing

This gem is signed using rubygems-openpgp using my personal key, and the fingerprint is also included below.

pub   4096R/CCFBB9EF 2013-02-01 [expires: 2017-02-01]
      Key fingerprint = 6077 34FC 32B6 6041 BF06  43F2 205D 9784 CCFB B9EF
uid                  Per Christian Bechström Viken <[email protected]>
uid                  [jpeg image of size 6240]
sub   4096R/13C6EED7 2013-02-01 [expires: 2017-02-01]

Licensing

The plugin is released under the MIT license.

TinyMCE is released under the LGPL Version 2.1.

The icon used for the button comes from the icon set Silk from famfamfam, released under the Creative Commons Attribution 3.0 License

tinymce-rails-imageupload's People

Contributors

abraham avatar alexjunger avatar arokettu avatar domon avatar dpc avatar ekubal avatar ffloyd avatar florentmorin avatar hefesto avatar imgarylai avatar inntran avatar klebervirgilio avatar nathanshox avatar nuno84 avatar perfectlynormal avatar pomartel avatar revgum avatar sobrinho avatar tjoneseng avatar wootenblatz avatar zakharday avatar zequez avatar znow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tinymce-rails-imageupload's Issues

It messes the absolute paths

After the image upload the server responds with the following:

{"image":{"url":"/tinymce_assets/AQEAAAAAAAAAB7Ho8_zNDQUAAA9CQA==.png"}}

And the editor displays the image just fine. However, once I persist the output that the editor generates the path gets messed up and turns into the following:

../tinymce_assets/AQEAAAAAAAAAB7Ho8_zNDQUAAA9CQA==.png

TinyMCE 4 compatibility

Hi @PerfectlyNormal ! I was just wondering if you had any plans to make the plugin compatible with the latest TinyMCE 4 release. I haven't found any good alternatives so far that works with Rails. Let me know!

Conflict with turbo assets?

I'm getting errors when deploying with capistrano and Rails3 turbo assets.. Can others reproduce this? The error I'm getting is:

 ** [out :: server] mkdir -p /u/apps/my_app/releases/20130305005446/public/assets
 ** [out :: server] 
 ** [out :: server] cp -r /u/apps/my_app/shared/bundle/ruby/1.9.1/gems/tinymce-rails-langs-0.1/vendor/assets/javascripts/tinymce /u/apps/my_app/releases/20130305005446/public/assets
 ** [out :: server] 
 ** [out :: server] mkdir -p /u/apps/my_app/releases/20130305005446/public/assets
 ** [out :: server] 
 ** [out :: server] cp -r /u/apps/my_app/shared/bundle/ruby/1.9.1/gems/tinymce-rails-imageupload-3.5.6.4/vendor/assets/javascripts/tinymce /u/apps/my_app/releases/20130305005446/public/assets
 ** [out :: server] 
 ** [out :: server] rake aborted!
 ** [out :: server] No such file or directory - /u/apps/my_app/releases/20130305005446/public/assets/tinymce/plugins/uploadimage/dialog-9cc16c48c2557a1254ec709a21ea5780.html

Removing rails3 turbo assets from the gemfile seems to fix the error (and removing this gem also seems to solve the error)

Uploader requires jQuery to work

Copied from #6

If you use following line in your main js file:
//= require tinymce
You will see the error message
tinyMCE.$ is not a function
in the JS console and the uploader will not work!
My solution is to use:
//= require tinymce-jquery
and it seems to work well!
Can you test it and make it run again?

Same file issue

Hi

The gem version 4, got updated, and when I try to deploy, this is happening:

rake aborted!
ArgumentError: same file: /home/app/releases/20170306133950/public/assets/tinymce/plugins/uploadimage/langs/da-7863a445de5898068b220fca3eca142f387ea9036f830c1a93416781d0f169a3.js and /home/findveji-production/releases/20170306133950/public/assets/tinymce/plugins/uploadimage/langs/da.js
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer/copy.rb:42:in `block in move_asset'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer.rb:58:in `with_asset'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer/copy.rb:5:in `with_asset'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer/copy.rb:40:in `move_asset'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer/copy.rb:23:in `block (2 levels) in cleanup_assets'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_manifest.rb:111:in `block in remove_digest'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_manifest.rb:23:in `asset_path'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_manifest.rb:107:in `remove_digest'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer/copy.rb:22:in `block in cleanup_assets'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_manifest.rb:16:in `block in each'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_manifest.rb:14:in `each_key'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_manifest.rb:14:in `each'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer/copy.rb:21:in `cleanup_assets'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer/copy.rb:12:in `call'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-4.5.4/lib/tinymce/rails/asset_installer.rb:22:in `install'
/home/app/shared/bundle/ruby/2.3.0/gems/tinymce-rails-imageupload-4.0.17.beta/lib/tasks/tinymce-uploadimage-assets.rake:13:in `block in <top (required)>'
/home/app/shared/bundle/ruby/2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

doubt

where to put the json function

cant get it to work

only the regular insert-image button shows. does anyone have a working setup?
thx

i have the yml file, i tried via:

<%= tinymce_assets %>
<%= tinymce :theme => "advanced", :plugins=> "uploadimage" %>

also via:

<script type="text/javascript">
tinyMCE.init({
  mode : "textareas",
  theme : "advanced",
  editor_selector : "mceEditor",
  plugins : "uploadimage"
});

but it doesnt show...anyone please? thx

Set Content-Type to application/json in response

I noticed that the plugin doesn't work if you actually return a json response. It seems to only work if you send a text/html response with json in it. I assume this is due to the way that the response is being parsed in the javascript.

Great start on a simple upload plugin though. Would be great to extend it and include a list view as well with a configurable endpoint for pulling in the image details.

Thanks!

Update translations before releasing new version

Would be nice to have the Portugese and Russian translations updated before releasing a new version. Any chance of some quick assistance with this?

Added:

# Used as the alt text for the progress spinner
uploading: "Uploading…",

# Error message when no file is chosen
blank_input: "Must choose a file",

# Error message when parsing the (JSON) response failed 
bad_response: "Got a bad response from the server",

# Error message when no response, or something else messed up
blank_response: "Didn't get a response from the server",

/cc @ffloyd, @Hefesto

unable to upload the image

Hi,
Am getting error while uploading image using tinymce-rails-imageupload, the error shows in my rails server console is....

  NoMethodError (undefined method `permit' for #<ActiveSupport::HashWithIndifferentAccess:0xb2c5410>):

app/controllers/tinymce_assets_controller.rb:7:in `create'

here are the details what i have configured as:

In my model: image.rib
class Image < ActiveRecord::Base
has_attached_file :file
belongs_to :user
belongs_to :event
end

In my controller: tinymce_assets_controller.rb
respond_to :json

def create
  geometry = Paperclip::Geometry.from_file(params[:file])
  image    = Image.create params.permit(:file, :alt, :hint)
  render json: {
    image: {
      url:    image.file.url,
      height: geometry.height.to_i,
      width:  geometry.width.to_i
    }
  }, layout: false, content_type: "text/html"
end

In my routes.rb
post '/tinymce_assets' => 'tinymce_assets#create'

In data migration: create_images.rb
class CreateImages < ActiveRecord::Migration
def change
create_table :images do |t|
t.string :alt, default: ""
t.string :hint, default: ""
t.attachment :file
t.timestamps
end
end
end

And my environment details are:
Ubuntu 12.04, ruby 1.9.3, rails 3.2.13, tinymce-rails 4.1.5 with tinymce-rails-imageupload.. and firefox 32. please let me know if you need some more details for verification.

Please help me! suggest me! guide me! point me! :) Thanks a LOT in Advance.

Thumbnails broken due to relative paths

I'm using your gem in a Rails project that uses Active Admin. It provides forms for creating/editing models, at preset routes.

When creating a new model, the form is located at:

/admin/model_name/new

When editing a model, it is located at:

/admin/model_name/model_id/edit

Since the forms are at a different depth, images I uploaded while creating the model don't show up when editing it, as their relative paths point to the wrong location. This only affects the editor and said images have the correct paths otherwise.

POST \ GET request issues.

It works just fine in Development (funny enough it used to work also in Production). The problem is that on production it issues the wrong GET request:

ActionController::RoutingError (No route matches [GET] "/at/tinymce_assets"):
Two issues here: Firstly - it puts a locale in front, secondly it uses a GET request.

On development however it works fine:

Started POST "/tinymce_assets" for 127.0.0.1 at 2015-09-27 02:33:10 +0200 Processing by TinymceAssetsController#create as HTML
My routes.rb looks like this:

Rails.application.routes.draw do root to: 'static_pages#redirect' localized do match '', to: 'static_pages#welcome', :as => 'welcome', via: 'get' ... lots of other stuff ... end match '*path', to: redirect("/#{I18n.locale}/%{path}"), constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" }, via: 'get' post '/tinymce_assets/' => 'tinymce_assets#create', :trailing_slash => false end
I am adding here the :trailing_slash => false - as it is set to true in environment.rb

Question:

Why does the production to site decide to fire a GET request + adding the locale, but the development does everything its supposed to do? Where can I set this behaviour, or is this a but in imageupload ?

http://stackoverflow.com/questions/32803453/rails-tinymce-imageupload-is-requesting-get-instead-of-post-as-in-development

Does not play nice with asset hosts

Unsafe JavaScript attempt to access frame with URL 
http://example.com/controller/action from frame with URL 
http://assets.example.com/tinymce/plugins/uploadimage/dialog.html?3.4.8. 
Domains, protocols and ports must match.`

RuntimeError: unknown file type

RuntimeError: unknown file type: /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/tinymce-rails-imageupload-4.0.17.beta.2/vendor/assets/javascripts/tinymce

    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:1387 :in `copy`
    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:472 :in `block in copy_entry`
    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:1498 :in `wrap_traverse`
    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:469 :in `copy_entry`
    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:444 :in `block in cp_r`
    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:1571 :in `block in fu_each_src_dest`

    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:1585 :in `fu_each_src_dest0`
    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:1569 :in `fu_each_src_dest`
    /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/fileutils.rb:443 :in `cp_r`
    [GEM_ROOT]/gems/tinymce-rails-4.5.6/lib/tinymce/rails/asset_installer/copy.rb:30 :in `copy_assets`
    [GEM_ROOT]/gems/tinymce-rails-4.5.6/lib/tinymce/rails/asset_installer/copy.rb:13 :in `call`
    [GEM_ROOT]/gems/tinymce-rails-4.5.6/lib/tinymce/rails/asset_installer.rb:22 :in `install`
    [GEM_ROOT]/gems/tinymce-rails-imageupload-4.0.17.beta.2/lib/tasks/tinymce-uploadimage-assets.rake:15 :in `block in <top (required)>` 

Custom language files not precompiled

It seems the fix for issue #5 and issue #14 doesn't take into account custom language files created in vendor/assets/javascripts/tinymce/plugins/uploadimage/langs in your application as instructed in the README.

So the custom languages files are not precompiled, and therefore there are missing in production environment.

The current workaround - as suggested in issue #5 - is to add them manually to config.assets.precompile.

4.0.0-beta assets problem

I wanted to test 4.0.0-beta version and I have problems with assets. After lunching my app I see following problem in my JS console:

JSsc

And when I add //= require tinymce/plugins/uploadimage/langs/en.js as I used to in previous versions of gem the following error appears:

JSsc

I really like your gem and looking forward to use it with version 4 of TinyMCE.

Missing coffescript on gemspec

I'm not using coffescript on my application:

16:24:20 web.1  | WARN: tilt autoloading 'coffee_script' in a non thread-safe way; explicit require 'coffee_script' suggested.
16:24:20 web.1  | Started GET "/assets/tinymce/plugins/uploadimage/editor_plugin.js?3.5.8" for 127.0.0.1 at 2012-12-09 16:24:20 -0200
16:24:20 web.1  | Error compiling asset tinymce/plugins/uploadimage/editor_plugin.js:
16:24:20 web.1  | LoadError: cannot load such file -- coffee_script
16:24:20 web.1  |   (in /Users/sobrinho/Developer/code5/ace/vendor/bundle/ruby/1.9.1/gems/tinymce-rails-imageupload-3.5.6.3/app/assets/javascripts/tinymce/plugins/uploadimage/editor_plugin.js.coffee)
16:24:20 web.1  | Served asset /tinymce/plugins/uploadimage/editor_plugin.js - 500 Internal Server Error

Maybe we should use plain javascript here to avoid an extra dependency (regardless the large adoption of coffescript) or just add it to gemspec.

TinyMCE 4

Tracking progress for TinyMCE 4 compatibility in a separate issue.

Done

  • It doesn't seem to actually submit the values in the form
  • Dialog misses styling
  • Spinner (throbber) doesn't work. It gets appended, but the automatic height calculating has already given the container height: 0px;
  • Should see if it's possible to drop dialog.html and use the new way of creating dialogs (had trouble getting a <input type='file'> in there)
  • Icon needs to be improved (#37)
  • Should add the action to the menu bar as well as the button bar
  • Make sure the hint and authentication_token still gets submitted
  • Support POSTing to configurable path
  • form drops the name attribute on our inputs
  • Parse response and insert the image
  • Pressing enter while in the form should submit it properly, not just close the window
  • Inserted image gets the wrong alt-text
  • Error handling is absent
  • Don't submit without an image
  • README talks about uploadimage_default_img_class, so keep that working
  • Get the form not looking like ass (inputs float everywhere)
  • Drop the border around the file input
  • Preload the throbber so we don't have to wait for it

Waiting

  • Test precompiling under Rails 3.2 and 4, since that tends to be a mess

Release preparations

  • Clean up the code
  • Extensive testing in IE8+, Firefox, Safari, Chrome and others we might care about
  • I have no idea how to fix proper automated tests for this, or what to test, but we should have some…
  • Make a proper beta release

Some of these probably work, but haven't been tested just yet.

No upload progress shown

At least not in Chrome. Might look like nothing is happening for bigger images, making the user click again. Should disable the buttons, and maybe show some kind of progress

Rails 4.2 doesnt return url

Hi) I'm using rails 4.2.5. I was following setup instructions, but get fail. When i uploadting file - it doesn't return url in json, but my page with editor in json format.
whats wrong?

 class TinymceAssetsController < ApplicationController
    respond_to :json

    def create
     geometry = Paperclip::Geometry.from_file params[:file]
     image    = Image.create params.permit(:file, :alt, :hint)
     authorize image

     render json: {
       image: {
         url:    image.file.url,
         height: geometry.height.to_i,
         width:  geometry.width.to_i
       }
     }, layout: false, content_type: "text/html"
   end
 end 



class Image < ActiveRecord::Base
  has_attached_file :file
  validates_attachment_content_type :file, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
end

Image upload failed inside HTTPS site

Hi,

It's a bit complicated because I don't know if the bug come from this gem or from the javascript library. I use your last version 4.X and when I want to upload image on my https site it fails. However just few days ago I have no problem without https. Perhaps the problem come from the use of http in the url for picture.

Do you have any clues on this behaviour or other people with same problem? Thanks for your time and your work!

Image in app/models :

class Image < ActiveRecord::Base

  # Accessible attributes
  attr_accessible :file,
                  :alt,
                  :hint

  # Attached files
  has_attached_file :file,
                    :styles => { :tinymce => "800>"},
                    :default_url => ""

  validates_attachment_content_type :file, :content_type => /\Aimage\/.*\Z/
  validates_with AttachmentSizeValidator, attributes: :file, less_than: 1.megabyte
end 

TinymceAssetsController in app/controllers

class TinymceAssetsController < ApplicationController
  respond_to :json

  def create
    image = Image.create params.slice(:file, :alt, :hint)

    render json: {
      image: {
          url: image.file.url(:tinymce)
      }
    }, layout: false, content_type: "text/html"

  end

end

Best Regards
Luc Donnet

tinymce editor disappears when specifying plugin in application.js

Hi, my tinymce editor seems to disappear with this setup. What am I doing wrong?

    tinyMCE.init({
      selector: "textarea.tinymce",
      menubar : false,
      theme : "modern",
      plugins: "uploadimage"
    });```

view:

<%= f.text_area :description, :class => "tinymce", :rows => 4, :cols => 100 %>
Thanks!

additional parameter in upload?

hi, is it possible to have additional parameters in the upload form? would be nice if eg it would pick up a predefined array or sthing where u can set the parameter. i need that for assigning the right 'image-folder'. (has_many-paperclipsmodels)

thx

Insert button doesn't work

Im clicking on the insert button to start uploading the image, but nothing happens. Am I missing something?

Is there somewhere I can see an example of a setup Controller? Sorry, I followed the instructions but this part was quite unclear for a newbie...

Upload file type error

Hello,

I have read the documentation and I'm sorry if I missed it but I'm looking for a way to display an error to the user if the file is not an image. (jpg, png, gif)

I see two ways : Verify the extension before upload
return a JSON error.

My project is already checking the extension and refuses non image file but if I return an empty JSON or an error, the upload form just hangs without doing anything.

Thanks a lot fort this very useful project by the way. I'm not very familiar iwth github projects and I have translated to French the JS. Could I send them you by email ?

Regards,

Harold

Version Tinymce 4

gem "tinymce-rails-imageupload", :git => 'git://github.com/PerfectlyNormal/tinymce-rails-imageupload.git'

There was a ArgumentError while loading tinymce-rails-imageupload.gemspec:
Malformed version number string 4.0.0-alpha.1 from
/Users/x/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/tinymce-rails-imageupload-0137c95da882/tinymce-rails-imageupload.gemspec:7:in
`block in

'

Extra functionality

I hacked around it and added functionality to also support other file types. In case it's image, it adds the image, otherwise it adds a link to the upload.

The hack consists in:
a. adding an extra json variable (isimage) which is 'true' if file type match(/image/).
b.if isimage=='true' as is else, create an tag instead of a
c.change the icon for the toolbar and some mesages

It is a very well formed plugin, thanks for having written it.

Image not rendering in TinyMCE on model edit action only

Hi

First off thanks for an awesome gem. It works really well but I am having a problem which I can't seem to figure out. I copied your demo exactly (this one: https://github.com/PerfectlyNormal/tinymce-rails-imageupload-demo) and uploading images to a page works fine. When I look at the page show action it works fine too but when i go to the edit action it shows a broken image. It is adding '/pages/' to the beginning of the image file path so the file path is

http://localhost:3000/pages/system/images/files/000/000/001/original/image.jpeg?1419121557

when it should be:

http://localhost:3000/system/images/files/000/000/001/original/image.jpeg?1419121557

Any insights on how to fix this would be much appreciated.

Thanks

Rory

rake assets:precompile breaks in tinymce-rails-imageupload 3.5.8.5 and TinyMCE-rails 3.5.8.3

Gem versions:

tinymce-rails-imageupload 3.5.8.5
TinyMCE-rails 3.5.8.3

Asset settings in production.rb (in the event they are relevant):

config.serve_static_assets = false
config.assets.css_compressor = :sass
config.assets.compile = false
config.assets.digest = true

I get the following error each time I attempt to run RAILS_ENV=production rake assets:precompile

Seems like the fix is as simple as passing the additional argument, but I wasn't sure if there was something else going on giving the assets being set on the above line.

Hope you have time to take a quick look! Thanks.

rake aborted!
wrong number of arguments (2 for 3)
/Users/carljhoover/.rvm/gems/ruby-1.9.3-p392/gems/tinymce-rails-3.5.8.3/lib/tinymce/rails/asset_installer.rb:6:in initialize'
/Users/carljhoover/.rvm/gems/ruby-1.9.3-p392/gems/tinymce-rails-imageupload-3.5.8.5/lib/tasks/tinymce-uploadimage-assets.rake:13:innew'
/Users/carljhoover/.rvm/gems/ruby-1.9.3-p392/gems/tinymce-rails-imageupload-3.5.8.5/lib/tasks/tinymce-uploadimage-assets.rake:13:in block in <top (required)>'
/Users/carljhoover/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:ineval'
/Users/carljhoover/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

Bug on Win7 IE9

Was it tested on IE9? When I try the plugin, it throws an exception when parsing the JSON in the handleResponse function. It's as if the document contains the html code of the main iframe instead of the hidden_upload iframe. Has anyone run into that issue?

CSRF-issues (again)

WARNING: Can't verify CSRF token authenticity in the log, and everything breaks. Needs some more investigation

Problem precompiling assets "Same file" error

I ran into a problem identical to the following open issue in the tinymce-rails project: spohlenz/tinymce-rails#183

In my reply to that issue I describe at least part of what causes the following crash:

Removing digest from public/assets/tinymce/plugins/uploadimage/langs/de-bef79730ed6c1394d01a609e466817ce.js
rake aborted!
public/assets/tinymce/plugins/uploadimage/langs/de-bef79730ed6c1394d01a609e466817ce.js and public/assets/tinymce/plugins/uploadimage/langs/de.js
~/.rvm/gems/ruby-2.1.5/gems/tinymce-rails-4.2.8/lib/tinymce/rails/asset_installer/copy.rb:42:in `block in move_asset'

The summary is that lib/tasks/tinymce-uploadimage-assets.rake probably needs to be updated to use the tinymce-rails configuration variable defined in application.rb (ie, :compile or :copy).

The fix is pretty simple but if you prefer I can issue a pull request for the following commit:
Wootenblatz@06db016

No route matches [GET] "/assets/tinymce/plugins/uploadimage/plugin.js"

Hi. First thanks for releasing/maintaining this gem. I'm using Rails 3.2.17, Ruby 2.0.0

gem "tinymce-rails"
gem 'tinymce-rails-imageupload', '~> 4.0.0.beta'
gem 'rack-cache', :require => 'rack/cache'
gem 'dragonfly', '~>0.9.14'
gem "paperclip"
gem "activeadmin"

tinymce-rails is version 4.0.19
activeadmin is version 0.6.3
paperclip is 3.5.1

I am hoping to add imageupload to tinymce-rails in activeadmin and I'm following your README and this tutorial. Everything works well locally.

When I deploy to heroku (cedar stack), the button in the toolbar does not appear and the logs read: ActionController::RoutingError No route matches [GET] "/assets/tinymce/plugins/uploadimage/plugin.js"

Running $ heroku run bash confirms that there is no uploadimage dir in the /public/assets/tinymce/plugins/ but there does appear to be an uploadimage dir at /public/assets . Attempts to mv it have thus far not solved the problem. Any thoughts?

other info

In active_admin.js.coffee

#= require active_admin/base
#= require tinymce
#= require chosen-jquery

$ ->
 tinymce.init
    browser_spellcheck: true
    selector: '.tinymce textarea'
    plugins: 'code link media uploadimage'
    menubar: 'edit format tools'
    toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | code link unlink | media uploadimage"

in config/routes

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

in tinymce_assets_controller

class TinymceAssetsController < ApplicationController
  def create
    @image = StaticImage.new(:page_image => params[:file])
    @image.save
    render json: {
      image: {
        url: @image.page_image.url
      }
    }, content_type: "text/html"
  end
end

Not precompiling

I'm not sure if there's something I'm missing, but trying to use this plugin on rails 3.2, the production environment can't find the js files unless I add them explicitly to config.assets.precompile. Are these supposed to be added to the tinymce-rails bundle automatically?

Compiling with tinymce-rails config.tinymce.install = :copy breaks.

I had to change this line inside lib/tasks/tinymce-uploadimage-asset.rake
assets = Pathname.new(File.expand_path(File.dirname(__FILE__) + "/../../vendor/assets/javascripts/tinymce"))
To.
assets = Pathname.new(File.expand_path(File.dirname(__FILE__) + "/../../app/assets/javascripts/tinymce"))

Otherwise I would get an "unknown file type" error

Wrong assets path

Hey,
I think this is tinymce.js problem, but if you got some workaround I would be thankfull

I got tinymce editor in view which is located in:
admin/blog_entries/:id/edit

When I try to upload pic I got this in editor:
<img src="/assets/blog_entry_images/283/large/xy.jpg?1486844369" alt="" width="640" height="300" data-mce-src="../../../assets/blog_ent.../>

when I save blog_entry to DB and then show it in frontend which is located at:
blog/2017/01/24/blog_entry_id

Picture doesn't show because link is: <img src="blog/assets/blog_entry_images/283/large/xy.jpg?1486844369">

Maintainer wanted

As most who look at this project probably can see, I haven't been paying too much attention to it lately. I hardly use TinyMCE anywhere anymore, so fixing bugs and improving things aren't something I can dedicate a lot of time to.

If anyone are interested in taking over and maintaining the project, let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.