javascript - TinyMCE editor doesn't initialize -
i'm building simple cms in ruby on rails , decided use wysiwyg editor syntax highlighting, chose tinymce. though, while trying use it, stuck couple of issues:
the first issue had error while trying run test blog cms. first included
s.add_dependency "tinymce-rails"
into mycms.gemspec
, ran
$ bundle install
then added
//= require tinymce
line application.js
in cms. when included cms plugin (which comes separate gem) test blog, couldn't reach admin panel because of error -- rails couldn't find tinymce
, need include gem tinymce-rails
in test app's gemfile work. (the same issue i've got gem bootstrap-sass
-- after including app's gemfile worked, though present in mycms.gemspec
the second issue editor doesn't initialize , not displayed in page. so, here comes form itself:
<%= form_for (@entry, as: :entry, url: entries_path) |f| %> <p> <%= f.label :title %> <br/> <%= f.text_field :title %> </p> <% @entry.class.content_attributes.each |attr_name, attr_type| %> <p> <%= f.label :title %><br /> <%= f.text_area attr_name, as: attr_type, class:"tinymce", rows:"40", cols:"120" %> </p> <% end %> <% end %> <%= tinymce %>
and textarea missing. tried variants -- included
//= require tinymce
or
//= require tinymce-jquery
both test app's application.js
or cms's application.js
, adding
<%= tinymce_assets %>
directly @ beginning of form, neither of these variants didn't work. have missed or done wrong?
the complete code of cms available on github
if haven't added javascript code, try adding this:
$(document).ready(function() { return tinymce.init({ selector: 'textarea', height: 100, width: 550, menubar: false, plugins: ['image', 'charmap', 'uploadimage'], toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link uploadimage | charmap ', theme: 'modern', relative_urls: false, remove_script_host: false, document_base_url: (!window.location.origin ? window.location.protocol + '//' + window.location.host : window.location.origin) + '/', setup: function(ed) { ed.on('init', function() { ed.getdoc().body.style.fontsize = '14px'; }); ed.on('change', function() { ed.save(); }); } }); });
Comments
Post a Comment