Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE and ActiveAdmin for Rails

I am reacquainting myself with Rails and I am really liking Active Admin. I would like to get tinyMCE working with it for use in text areas. However, any instructions I find are incomplete. For some reason, I think that I am missing something really simple here.

So, for example, I have tinymce-rails installed (3.4.9) and followed the instructions (https://github.com/spohlenz/tinymce-rails). However, here's where I think I failed: actually initiating tinyMCE. According to the doc, I have two options:

  1. use the <%= tinymce %> helper or...
  2. initialize it like the following tinyMCE.init({ mode: 'textareas', theme: 'advanced' });

I tried adding the latter to my active_admin.js file to no avail.

If someone could guide me on this, I would be most appreciative.

like image 752
JP Smith Avatar asked May 02 '12 02:05

JP Smith


1 Answers

I got it working doing the following things (outside of the install described at the repo)

In admin/my_class.rb:

ActiveAdmin.register MyClass do
  form do |f|
    f.inputs do 
      f.input :body, :input_html => { :class => "tinymce" }
    end
  end
end

In initializers/active_admin.rb:

...
config.register_javascript 'tinymce.js'

This was what actually got the tinymce.js script to show up in the head of the admin layout.

In javascripts/active_admin.js:

//= require active_admin/base
//= require tinymce

$(document).ready(function() {
  tinyMCE.init({
     mode: 'textareas',
     theme: 'advanced'
   });
});

After doing those things, that body input (text area) had a fully functioning editor on it.

like image 129
mcmaloney Avatar answered Oct 12 '22 11:10

mcmaloney