ruby-on-railstinymce-rails

Initializing tinymce-rails-image-upload using tinymce-rails


I'm trying to set up image uploading using the tinymce-image-upload gem and the tinymce-rails gem. I'm having trouble with one of the steps in the tinymce-image-upload setup:

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

Since I'm using tinymce-rails I have

<%= tinymce %>

at the bottom of the view to initialize tinymce. However, I'm not sure how to add:

plugins: "uploadimage"

In the demo it is added in the javascript like this:

<script type="text/javascript">
$("document:ready", function() {
 $("[rel=tinymce]").tinymce({
  theme: "modern",
  toolbar:    "bold,italic,underline,|,bullist,numlist,outdent,indent,|,undo,redo,|,pastetext,pasteword,selectall,|,uploadimage",
  pagebreak_separator: "<p class='page-separator'>&nbsp;</p>",
  plugins: ["uploadimage"],
  relative_urls: false,
  remove_script_host: false,
  document_base_url: (!window.location.origin ? window.location.protocol + "//" + window.location.host : window.location.origin) + "/",
   })
 });
</script>

Solution

  • According to the tinymce-rails docs, https://github.com/spohlenz/tinymce-rails/blob/master/README.md

    There are two ways to configure plugins:

    1) Use a yml config file for global settings (applied to all tinymce calls) config/tinymce.yml

    plugins:
      - uploadimage
    

    2) Include options as a hash in the tinymce method call:

    <%= tinymce plugins: ["uploadimage"] %>